amotolani / fmc_collections

Ansible Collections for Cisco FMC API
6 stars 4 forks source link

Fixed port_group deletion #12

Closed outlawww closed 2 years ago

outlawww commented 2 years ago

The same fix as with network_groups, when using "absent"


failed: [10.177.191.11] (item={'object_name': 'TOMCAT', 'object_members': 'TOMCAT-TCP,TOMCAT-UDP'}) => changed=false 
  ansible_loop_var: item
  item:
    object_members: TOMCAT-TCP,TOMCAT-UDP
    object_name: TOMCAT
  module_stderr: |-
    INFO:root:Requesting new tokens from https://10.177.191.11/api/fmc_platform/v1/auth/generatetoken.
    INFO:root:Building base to URLs.
    INFO:root:Populating vdbVersion, sruVersion, serverVersion, and geoVersion FMC instance variables.
    INFO:root:This FMC's version is 6.6.1 (build 91)
    INFO:root:GET success. Object with name: "TOMCAT" and id: "005056A1-EE5E-0ed3-0000-004294994140" fetched from FMC.
    INFO:root:Auto deploy changes set to False.  Use the Deploy button in FMC to push changes to FTDs.
    Traceback (most recent call last):
      File "/home/vscode/.ansible/tmp/ansible-tmp-1655993894.6210828-1609-186931382590140/AnsiballZ_port_group.py", line 102, in <module>
        _ansiballz_main()
      File "/home/vscode/.ansible/tmp/ansible-tmp-1655993894.6210828-1609-186931382590140/AnsiballZ_port_group.py", line 94, in _ansiballz_main
        invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)
      File "/home/vscode/.ansible/tmp/ansible-tmp-1655993894.6210828-1609-186931382590140/AnsiballZ_port_group.py", line 40, in invoke_module
        runpy.run_module(mod_name='ansible_collections.amotolani.cisco_fmc.plugins.modules.port_group', init_globals=None, run_name='__main__', alter_sys=True)
      File "/usr/local/lib/python3.8/runpy.py", line 207, in run_module
        return _run_module_code(code, init_globals, run_name, mod_spec)
      File "/usr/local/lib/python3.8/runpy.py", line 97, in _run_module_code
        _run_code(code, mod_globals, init_globals,
      File "/usr/local/lib/python3.8/runpy.py", line 87, in _run_code
        exec(code, run_globals)
      File "/tmp/ansible_amotolani.cisco_fmc.port_group_payload__72boe50/ansible_amotolani.cisco_fmc.port_group_payload.zip/ansible_collections/amotolani/cisco_fmc/plugins/modules/port_group.py", line 285, in <module>
      File "/tmp/ansible_amotolani.cisco_fmc.port_group_payload__72boe50/ansible_amotolani.cisco_fmc.port_group_payload.zip/ansible_collections/amotolani/cisco_fmc/plugins/modules/port_group.py", line 249, in main
    UnboundLocalError: local variable '_create_obj' referenced before assignment
  module_stdout: ''
  msg: |-
    MODULE FAILURE
    See stdout/stderr for the exact error
  rc: 1

playbook:

  - name: "{% if state == 'present' %}Creating{% else %}Deleting{% endif %} Port Groups..."
    amotolani.cisco_fmc.port_group:
      name: "{{item.object_name}}"
      state: absent
      fmc: "{{ ansible_host }}"
      action: add
      username: "{{ ansible_user }}"
      password: "{{ ansible_password }}"
      auto_deploy: false
      group_objects: "{{item.object_members}}"
    with_items: "{{ port_groups.list }}"
    tags: "port_groups"