Support Forum
The Forums are a place to find answers on a range of Fortinet products from peers and product experts.
hamenkiakehna
New Contributor

Ansible - Passing a dictionary to a module parameter

I'm using fortinet.fortios.system_global module as describe here: https://docs.ansible.com/ansible/latest/collections/fortinet/fortios/fortios_system_global_module.ht...springAcessories

My goal is to pass a dictionary to the system_global parameter with the allowed sub-parameters. I have the dictionary as follows for example:

forti:
  admin-concurrent: enable
  admin-console-timeout: 0
  admin-hsts-max-age: 15552000
  <more key:value>

This dictionary lives in a separate file called forti.yml. I then use include_vars to pull this yml file into my play as follows:

vars_files:
  - /path/to/forti.yml

And then I use the system_global module:

- name: Configure system_global task
  fortios_system_global:
    access: "{{ access_token }}"
    system_global: "{{ forti }}"

However, when I run the play it throws an error like so:

"msg": "Unsupported parameters for (fortios_system_global) module: system_global.admin-concurrent, system_global.admin-console-timeout, system_global.admin-hsts-max-age,<and so on>. Supported parameters include: member_path, member_state, system_global, vdom, enable_log, access_token."

I tried putting the key:value pairs in the vars: in the play level and passed it to the module the same way and it worked.

vars:
 forti:
   admin-concurrent: enable
   admin-console-timeout: 0
   admin-hsts-max-age: 15552000
   <more key: value>

What am I missing? They're both type: dict, the data are exactly the same. Not sure what I'm missing here. Can someone please help?

doodle kahan
1 REPLY 1
mbarbosa
Staff
Staff

Hi hamenkiakehna,

 

I was not able to reproduce your issue, I think you're using the wrong variable names. There shouldn't be any variables with dash, only underscore is accepted.

 

Here's my environment:

 

fortios_system_global.yml

#!/usr/bin/env ansible-playbook
---
- hosts: fws

  vars:
    system_global_vars:
      admin_concurrent: enable
      admin_login_max: 90

  tasks:
    - name: Update global config
      fortinet.fortios.fortios_system_global:
        access_token: "{{ fortios_access_token }}"
        system_global: "{{ system_global_vars }}"

 

It works as expected, so I created a new play to pull the variables from a file, here's my file/dir structure:

 

$ tree
.
├── README.md
├── ansible.cfg
├── fortios_system_global.yml
├── fortios_system_global_varsfile.yml
├── group_vars
│   ├── fws.yml
│   └── security_fabric.yml
├── host_vars
│   └── fortigate.yml
├── inventory.ini
├── requirements.txt
├── requirements.yml
└── vars
    └── sys_global_vars.yml

3 directories, 11 files

 

and the new play/vars file:

 

sys_global_vars.yml

---
system_global_vars:
  admin_concurrent: enable
  admin_login_max: 90

 

fortios_system_global_varsfile.yml

#!/usr/bin/env ansible-playbook
---
- hosts: fws

  tasks:
    - name: Load vars
      include_vars:
        file: sys_global_vars.yml

    - name: Update global config
      fortinet.fortios.fortios_system_global:
        access_token: "{{ fortios_access_token }}"
        system_global: "{{ system_global_vars }}"

 

Finally, here's the versions I used for this test:

 

requirements.yml

---
collections:
  - name: ansible.netcommon
    version: 2.6.1
  - name: fortinet.fortios
    version: 2.1.4

 

ansible --version

$ ansible --version
ansible [core 2.12.3]
  config file = /Users/draks/Documents/github/dev/tmp-ansible-fg/fortigate/ansible.cfg
  configured module search path = ['/Users/draks/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /Users/draks/.pyenv/versions/3.8.5/lib/python3.8/site-packages/ansible
  ansible collection location = /Users/draks/.ansible/collections:/usr/share/ansible/collections
  executable location = /Users/draks/.pyenv/versions/3.8.5/bin/ansible
  python version = 3.8.5 (default, Jan  1 2021, 16:01:51) [Clang 12.0.0 (clang-1200.0.32.28)]
  jinja version = 3.0.3
  libyaml = True

 

Can you please try using the same vars file I proposed here and let me know the results?

 

Regards,

Michel Barbosa

---
Michel Barbosa
NSE8 #3073