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

GNU General Public License v3.0
85 stars 49 forks source link

IndexError: list index out of range in module_utils/fortios/comparison.py #191

Closed dgarros closed 10 months ago

dgarros commented 2 years ago

I'm getting an list index out of range error when I execute the module fortios_firewall_policy

Looks like the error is coming from this code

#module_utils/fortios/comparison.py

if type(value) == dict:
    if not is_same_comparison(reorder_current[key], value):
        return False
elif type(value) == list:
    if len(value) != len(reorder_current[key]):
        return False
    if type(value[0]) == dict: <<<<<<<<<<<<<<<<<<
        for current_dict in reorder_current[key]:
            if not is_same_comparison(current_dict, value[0]):
                return False

I was able to fix it by replacing the line 78 with if len(value) and type(value[0]) == dict: instead of if type(value[0]) == dict:

I'd be happy to send a PR but not sure how that works for this project

Environment

Inputs

- name: Create/Update Policy Object
  fortinet.fortios.fortios_firewall_policy:
    vdom: "{{ vdom }}"
    state: "present"
    firewall_policy:
      action: accept
      application_list: REDACTED
      av_profile: REDACTED
      comments: REDACTED
      dnsfilter_profile: REDACTED
      dstaddr:
      - name: REDACTED
      dstintf:
      - name: any
      groups:
      - name: REDACTED
      inspection_mode: flow
      internet_service: disable
      internet_service_name: []
      ippool: disable
      ips_sensor: REDACTED
      name: REDACTED
      nat: disable
      policyid: 54
      service:
      - name: DNS
      - name: PING
      srcaddr:
      - name: all
      srcintf:
      - name: ssl.root
      ssl_ssh_profile: REDACTED
      utm_status: enable
      ztna_status: disable
JieX19 commented 2 years ago

Hi @dgarros,

Thanks for the detailed info! I can reproduce the error on 2.1.6. It should check the len(value) first, Thank you for finding the issue! I will fix it in the upcoming release.

JieX19 commented 10 months ago

Hi @dgarros

The error had been fixed in the fortios collection. I will close this issue at this moment and feel free to reopen it or open a new issue if you still have any questions.