Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong data type for fmgr_dvmdb_device_vdom #54

Open
vincent-at-forti opened this issue Nov 4, 2022 · 2 comments
Open

Wrong data type for fmgr_dvmdb_device_vdom #54

vincent-at-forti opened this issue Nov 4, 2022 · 2 comments

Comments

@vincent-at-forti
Copy link

Using ansible fmgr_dvmdb_device_vdom.py module to create a FGT vdom in FMG ADOM.
The query sent by ansible is the using a dictionary for the data :

 "params":[
      {
         "data":{ 
            "comments":"Commentaire",
            "name":"newVdomAnsible2",
            "opmode":"nat",				   
            "status":"present",
            "vpn_id":0
         },
         "target start":1,
         "url":"/dvmdb/adom/AdomAnsible/device/axion-api-kvm07/vdom"
      }
   ],

But the FMG API is waiting for a list of dict:

   "params":[
      {
         "data":[
            {
               "comments":"New vdom",
               "name":"test221",
               "opmode":"nat",
               "rtm_prof_id":0,
               "status":"present",
               "vpn_id":0
            }
         ],
         "target start":1,
         "url":"/dvmdb/adom/AdomAnsible/device/axion-api-kvm07/vdom"
      }
   ],

So FMG refuses with the following error:
{ "status": { "code": 1, "message": "runtime error 0: invalid value"}}

Maybe replacing the :

    dvmdb_device_vdom:
        description: the top level parameters set
        required: false
        type: dict
        suboptions:

by

  dvmdb_device_vdoms: 
          description: the top level parameters set
          required: false
          type: list
          suboptions:
@jpforcioli
Copy link

jpforcioli commented Dec 28, 2022

Hi,

Can't reproduce with fortinet.fortimanager 2.1.7 and FMG 7.2.2-INTERIM build 1311.

That's my playbook:

---
- hosts: 10.210.35.112
  connection: httpapi
  collections:
    - fortinet.fortimanager
  gather_facts: false
  vars:
    adom: dc_emea
    device: dut_fgt_01
    vdom: vd_001
  tasks:
  - name: Add VDOM {{ adom }}/{{ device }}[{{ vdom }}]
    fmgr_dvmdb_device_vdom:
      adom: "{{ adom }}"
      device: "{{ device }}"
      state: present
      dvmdb_device_vdom:
        name: "{{ vdom }}"
        comments: Created with fortinet.fortimananager collection
        opmode: nat

That's the debug output from FMG:

diagnose debug service dvmdb 255
diagnose debug timestamp enable
diagnose enable
[...]
2022-12-28 08:18:14 { "client": "\/usr\/local\/apache2\/bin\/httpd:29562", "id": 7, "method": "set", "params": [{ "data": { "comments": "Created with fortinet.fortimananager collection", "name": "vd_001", "opmode": "nat"}, "target start": 1, "url": "\/dvmdb\/adom\/dc_emea\/device\/dut_fgt_01\/vdom"}], "session": "BbCFuzVn04adnXoEc9eCLzsiXiWknz3aHYaM7+oLINOk8h04RAYvK624WsZEw\/riiFE0QCUmxGr+b3zjp1n8K00jR8BZmWU5", "src": "172.26.139.195", "verbose": 1}
[...]

Once pretty formatted the JSON payload is:

{
  "client": "/usr/local/apache2/bin/httpd:29562",
  "id": 7,
  "method": "set",
  "params": [
    {
      "data": {
        "comments": "Created with fortinet.fortimananager collection",
        "name": "vd_001",
        "opmode": "nat"
      },
      "target start": 1,
      "url": "/dvmdb/adom/dc_emea/device/dut_fgt_01/vdom"
    }
  ],
  "session": "BbCFuzVn04adnXoEc9eCLzsiXiWknz3aHYaM7+oLINOk8h04RAYvK624WsZEw/riiFE0QCUmxGr+b3zjp1n8K00jR8BZmWU5",
  "src": "172.26.139.195",
  "verbose": 1
}

We can see the data is a dict (not a list) and it is working.

(Also checked in FNDN and the specs for the data doesn't mention it has to be a list).

Would you mind explaining how you got that conclusion that data should be a list?

Best Regards.

@jpforcioli
Copy link

jpforcioli commented Dec 28, 2022

And I just realized that you passed:

"status": "present"

in your data block.

present is for Ansible :-)
This status placed within the data dict is for FortiManager; it expects either an enable or a disable :-)
But it doesn't explain your problem; I've tested with present and it still works.

BR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants