Ansible - Passing a dictionary to a module parameter

Viewed 64

I'm using fortinet.fortios.system_global module as describe here: https://docs.ansible.com/ansible/latest/collections/fortinet/fortios/fortios_system_global_module.html#ansible-collections-fortinet-fortios-fortios-system-global-module

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?

1 Answers

You have - and the parameters are supposed to be _ so it is telling you the module parameter does not exist

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

should be

vars:
 forti:
   admin_concurrent: enable
   admin_console_timeout: 0
   admin_hsts_max_age: 15552000
   <more key: value>

Keep on automating!

Just look at module examples here: https://docs.ansible.com/ansible/latest/collections/fortinet/fortios/fortios_system_global_module.html#ansible-collections-fortinet-fortios-fortios-system-global-module

Related