fortinet-ansible-dev / ansible-galaxy-fortios-collection

GNU General Public License v3.0
84 stars 47 forks source link

check mode error since 2.3.5 #309

Open grenotjg opened 2 months ago

grenotjg commented 2 months ago

Hi everyone,

The check for the fortios_firewall_address seems broken when the address already exists. Everything is OK when the address doesn't exist.

The following code works in 2.3.4 --check --diff

tasks:
  - name: Creating_adresse_STDADR
    fortios_firewall_address:
      vdom: "{{ vdom_name }}"
      state: "{{ item.value.state }}"
      access_token: "{{ access_token_forti }}"
      firewall_address:
        name: "{{ item.value.name }}"
        type: "{{ item.value.type }}"
        subnet: "{{ item.value.subnet | default(omit) }}"
        start_ip: "{{ item.value.start_ip | default(omit) }}"
        end_ip: "{{ item.value.end_ip | default(omit) }}"
        associated_interface: "EXTERNAL"
        color: "19"
        comment: "{{ item.value.comment }}"
    loop: "{{ stdadr_list|dict2items }}"
    when: standard_select =="" or standard_select == item.value.name
    register: result
    ignore_errors: yes

Here is the error message with 2.3.5 KeyError: 0

MODULE_STDERR:

Traceback (most recent call last):
  File "/Users/jgo/.ansible/tmp/ansible-local-9726t00g9_9w/ansible-tmp-1713781300.07883-9768-11783409384410/AnsiballZ_fortios_firewall_address.py", line 107, in <module>
    _ansiballz_main()
  File "/Users/jgo/.ansible/tmp/ansible-local-9726t00g9_9w/ansible-tmp-1713781300.07883-9768-11783409384410/AnsiballZ_fortios_firewall_address.py", line 99, in _ansiballz_main
    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)
  File "/Users/jgo/.ansible/tmp/ansible-local-9726t00g9_9w/ansible-tmp-1713781300.07883-9768-11783409384410/AnsiballZ_fortios_firewall_address.py", line 47, in invoke_module
    runpy.run_module(mod_name='ansible_collections.fortinet.fortios.plugins.modules.fortios_firewall_address', init_globals=dict(_module_fqn='ansible_collections.fortinet.fortios.plugins.modules.fortios_firewall_address', _modlib_path=modlib_path),
  File "<frozen runpy>", line 226, in run_module
  File "<frozen runpy>", line 98, in _run_module_code
  File "<frozen runpy>", line 88, in _run_code
  File "/var/folders/7w/lt91rj8579g829_7hckb_b2r0000gn/T/ansible_fortios_firewall_address_payload_ngs6cvv8/ansible_fortios_firewall_address_payload.zip/ansible_collections/fortinet/fortios/plugins/modules/fortios_firewall_address.py", line 999, in <module>
  File "/var/folders/7w/lt91rj8579g829_7hckb_b2r0000gn/T/ansible_fortios_firewall_address_payload_ngs6cvv8/ansible_fortios_firewall_address_payload.zip/ansible_collections/fortinet/fortios/plugins/modules/fortios_firewall_address.py", line 965, in main
  File "/var/folders/7w/lt91rj8579g829_7hckb_b2r0000gn/T/ansible_fortios_firewall_address_payload_ngs6cvv8/ansible_fortios_firewall_address_payload.zip/ansible_collections/fortinet/fortios/plugins/modules/fortios_firewall_address.py", line 710, in fortios_firewall
  File "/var/folders/7w/lt91rj8579g829_7hckb_b2r0000gn/T/ansible_fortios_firewall_address_payload_ngs6cvv8/ansible_fortios_firewall_address_payload.zip/ansible_collections/fortinet/fortios/plugins/modules/fortios_firewall_address.py", line 649, in firewall_address
  File "/var/folders/7w/lt91rj8579g829_7hckb_b2r0000gn/T/ansible_fortios_firewall_address_payload_ngs6cvv8/ansible_fortios_firewall_address_payload.zip/ansible_collections/fortinet/fortios/plugins/module_utils/fortios/comparison.py", line 124, in serialize
KeyError: 0

An exception occurred during task execution. To see the full traceback, use -vvv. The error was: KeyError: 0
failed: [vdom_TESTJGS] (item={'key': 'STDADR_I002', 'value': {'name': 'TEST_ADMIN_PAR2', 'type': 'ipmask', 'subnet': '10.59.23.1 255.255.255.255', 'state': 'present', 'comment': 'STDADR #14340'}}) => {
    "ansible_loop_var": "item",
    "changed": false,
    "item": {
        "key": "STDADR_I002",
        "value": {
            "comment": "STDADR #14340",
            "name": "TEST_ADMIN_PAR2",
            "state": "present",
            "subnet": "10.59.23.1 255.255.255.255",
            "type": "ipmask"
        }
    },
    "rc": 1
}

Here is the error with 2.3.6 KeyError: 'associated_interface'

MODULE_STDERR:

Traceback (most recent call last):
  File "/Users/jgo/.ansible/tmp/ansible-local-9594id42gony/ansible-tmp-1713781256.890196-9634-222015980056994/AnsiballZ_fortios_firewall_address.py", line 107, in <module>
    _ansiballz_main()
  File "/Users/jgo/.ansible/tmp/ansible-local-9594id42gony/ansible-tmp-1713781256.890196-9634-222015980056994/AnsiballZ_fortios_firewall_address.py", line 99, in _ansiballz_main
    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)
  File "/Users/jgo/.ansible/tmp/ansible-local-9594id42gony/ansible-tmp-1713781256.890196-9634-222015980056994/AnsiballZ_fortios_firewall_address.py", line 47, in invoke_module
    runpy.run_module(mod_name='ansible_collections.fortinet.fortios.plugins.modules.fortios_firewall_address', init_globals=dict(_module_fqn='ansible_collections.fortinet.fortios.plugins.modules.fortios_firewall_address', _modlib_path=modlib_path),
  File "<frozen runpy>", line 226, in run_module
  File "<frozen runpy>", line 98, in _run_module_code
  File "<frozen runpy>", line 88, in _run_code
  File "/var/folders/7w/lt91rj8579g829_7hckb_b2r0000gn/T/ansible_fortios_firewall_address_payload_8kqoiy4f/ansible_fortios_firewall_address_payload.zip/ansible_collections/fortinet/fortios/plugins/modules/fortios_firewall_address.py", line 976, in <module>
  File "/var/folders/7w/lt91rj8579g829_7hckb_b2r0000gn/T/ansible_fortios_firewall_address_payload_8kqoiy4f/ansible_fortios_firewall_address_payload.zip/ansible_collections/fortinet/fortios/plugins/modules/fortios_firewall_address.py", line 942, in main
  File "/var/folders/7w/lt91rj8579g829_7hckb_b2r0000gn/T/ansible_fortios_firewall_address_payload_8kqoiy4f/ansible_fortios_firewall_address_payload.zip/ansible_collections/fortinet/fortios/plugins/modules/fortios_firewall_address.py", line 700, in fortios_firewall
  File "/var/folders/7w/lt91rj8579g829_7hckb_b2r0000gn/T/ansible_fortios_firewall_address_payload_8kqoiy4f/ansible_fortios_firewall_address_payload.zip/ansible_collections/fortinet/fortios/plugins/modules/fortios_firewall_address.py", line 642, in firewall_address
  File "/var/folders/7w/lt91rj8579g829_7hckb_b2r0000gn/T/ansible_fortios_firewall_address_payload_8kqoiy4f/ansible_fortios_firewall_address_payload.zip/ansible_collections/fortinet/fortios/plugins/module_utils/fortios/comparison.py", line 103, in find_current_values
KeyError: 'associated_interface'

Regards,

MaxxLiu22 commented 2 months ago

Hi @grenotjg ,

Thank you for raising this issue. I can reproduce it, and the error may have been caused by our special keyword handling in the last release. I have reported it to the development team for fixing.

Thanks, Maxx

grenotjg commented 2 months ago

Thanks Maxx !

MaxxLiu22 commented 3 hours ago

Hi @grenotjg

We just released Ansible FOS 2.3.7. This issue should be fixed, so you could upgrade to it and give it a try at your convenience.

ansible-galaxy collection install fortinet.fortios:2.3.7

Thanks, Maxx