Skip to content

panos_device_group errors when firewalls exists in child device groups #611

Open
@mhca99

Description

@mhca99

Describe the bug

We can create device group with panos_device_group on first ansible run, however , when later firewalls added to child device group , running panos_device_group produces following error:

An exception occurred during task execution. To see the full traceback, use -vvv. The error was: TypeError: Firewall.element() got an unexpected keyword argument 'comparable'
failed: [panvm01] (item={'group_name': 'dev_dg', 'parent': 'site_dg'}) => {"ansible_loop_var": "item", "changed": false, "item": {"group_name": "dev_dg", "parent": "site_dg"}, "module_stderr": "Traceback (most recent call last):\n  File \"/tmp/ansible_paloaltonetworks.panos.panos_device_group_payload_dyhih3b8/ansible_paloaltonetworks.panos.panos_device_group_payload.zip/ansible_collections/paloaltonetworks/panos/plugins/module_utils/panos.py\", line 79, in eltostr\n  File \"/home/ansibleuser/.local/lib/python3.12/site-packages/panos/base.py\", line 531, in element_str\n    raw = ET.tostring(self.element(), encoding=\"utf-8\")\n                      ^^^^^^^^^^^^^^\n  File \"/home/ansibleuser/.local/lib/python3.12/site-packages/panos/base.py\", line 2615, in element\n    self.xml_merge(ans, itertools.chain(*iterchain))\n  File \"/home/ansibleuser/.local/lib/python3.12/site-packages/panos/base.py\", line 1699, in xml_merge\n    for e in elements:\n  File \"/home/ansibleuser/.local/lib/python3.12/site-packages/panos/base.py\", line 573, in _subelements\n    e.append(child.element(comparable=comparable))\n             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\nTypeError: Firewall.element() got an unexpected keyword argument 'comparable'\n\nDuring handling of the above exception, another exception occurred:\n\nTraceback (most recent call last):\n  File \"/home/ansibleuser/.ansible/tmp/ansible-tmp-1743454166.7201355-2455-79811992496125/AnsiballZ_panos_device_group.py\", line 107, in <module>\n    _ansiballz_main()\n  File \"/home/ansibleuser/.ansible/tmp/ansible-tmp-1743454166.7201355-2455-79811992496125/AnsiballZ_panos_device_group.py\", line 99, in _ansiballz_main\n    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\n  File \"/home/ansibleuser/.ansible/tmp/ansible-tmp-1743454166.7201355-2455-79811992496125/AnsiballZ_panos_device_group.py\", line 47, in invoke_module\n    runpy.run_module(mod_name='ansible_collections.paloaltonetworks.panos.plugins.modules.panos_device_group', init_globals=dict(_module_fqn='ansible_collections.paloaltonetworks.panos.plugins.modules.panos_device_group', _modlib_path=modlib_path),\n  File \"<frozen runpy>\", line 226, in run_module\n  File \"<frozen runpy>\", line 98, in _run_module_code\n  File \"<frozen runpy>\", line 88, in _run_code\n  File \"/tmp/ansible_paloaltonetworks.panos.panos_device_group_payload_dyhih3b8/ansible_paloaltonetworks.panos.panos_device_group_payload.zip/ansible_collections/paloaltonetworks/panos/plugins/modules/panos_device_group.py\", line 157, in <module>\n  File \"/tmp/ansible_paloaltonetworks.panos.panos_device_group_payload_dyhih3b8/ansible_paloaltonetworks.panos.panos_device_group_payload.zip/ansible_collections/paloaltonetworks/panos/plugins/modules/panos_device_group.py\", line 153, in main\n  File \"/tmp/ansible_paloaltonetworks.panos.panos_device_group_payload_dyhih3b8/ansible_paloaltonetworks.panos.panos_device_group_payload.zip/ansible_collections/paloaltonetworks/panos/plugins/module_utils/panos.py\", line 516, in process\n  File \"/tmp/ansible_paloaltonetworks.panos.panos_device_group_payload_dyhih3b8/ansible_paloaltonetworks.panos.panos_device_group_payload.zip/ansible_collections/paloaltonetworks/panos/plugins/module_utils/panos.py\", line 702, in apply_state\n  File \"/tmp/ansible_paloaltonetworks.panos.panos_device_group_payload_dyhih3b8/ansible_paloaltonetworks.panos.panos_device_group_payload.zip/ansible_collections/paloaltonetworks/panos/plugins/module_utils/panos.py\", line 82, in eltostr\n  File \"/home/ansibleuser/.local/lib/python3.12/site-packages/panos/base.py\", line 534, in element_str\n    return ET.tostring(self.element(), encoding=\"utf-8\")\n                       ^^^^^^^^^^^^^^\n  File \"/home/ansibleuser/.local/lib/python3.12/site-packages/panos/base.py\", line 2615, in element\n    self.xml_merge(ans, itertools.chain(*iterchain))\n  File \"/home/ansibleuser/.local/lib/python3.12/site-packages/panos/base.py\", line 1699, in xml_merge\n    for e in elements:\n  File \"/home/ansibleuser/.local/lib/python3.12/site-packages/panos/base.py\", line 573, in _subelements\n    e.append(child.element(comparable=comparable))\n             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\nTypeError: Firewall.element() got an unexpected keyword argument 'comparable'\n", "module_stdout": "", "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error", "rc": 1}

An exception occurred during task execution. To see the full traceback, use -vvv. The error was: TypeError: Firewall.element() got an unexpected keyword argument 'comparable'
failed: [panvm01] (item={'group_name': 'dev_dg', 'parent': 'site_dg'}) => {"ansible_loop_var": "item", "changed": false, "item": {"group_name": "dev_dg", "parent": "site_dg"}, "module_stderr": "Traceback (most recent call last):\n File "/tmp/ansible_paloaltonetworks.panos.panos_device_group_payload_dyhih3b8/ansible_paloaltonetworks.panos.panos_device_group_payload.zip/ansible_collections/paloaltonetworks/panos/plugins/module_utils/panos.py", line 79, in eltostr\n File "/home/ansibleuser/.local/lib/python3.12/site-packages/panos/base.py", line 531, in element_str\n raw = ET.tostring(self.element(), encoding="utf-8")\n ^^^^^^^^^^^^^^\n File "/home/ansibleuser/.local/lib/python3.12/site-packages/panos/base.py", line 2615, in element\n self.xml_merge(ans, itertools.chain(*iterchain))\n File "/home/ansibleuser/.local/lib/python3.12/site-packages/panos/base.py", line 1699, in xml_merge\n for e in elements:\n File "/home/ansibleuser/.local/lib/python3.12/site-packages/panos/base.py", line 573, in _subelements\n e.append(child.element(comparable=comparable))\n ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\nTypeError: Firewall.element() got an unexpected keyword argument 'comparable'\n\nDuring handling of the above exception, another exception occurred:\n\nTraceback (most recent call last):\n File "/home/ansibleuser/.ansible/tmp/ansible-tmp-1743454166.7201355-2455-79811992496125/AnsiballZ_panos_device_group.py", line 107, in \n _ansiballz_main()\n File "/home/ansibleuser/.ansible/tmp/ansible-tmp-1743454166.7201355-2455-79811992496125/AnsiballZ_panos_device_group.py", line 99, in _ansiballz_main\n invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\n File "/home/ansibleuser/.ansible/tmp/ansible-tmp-1743454166.7201355-2455-79811992496125/AnsiballZ_panos_device_group.py", line 47, in invoke_module\n runpy.run_module(mod_name='ansible_collections.paloaltonetworks.panos.plugins.modules.panos_device_group', init_globals=dict(_module_fqn='ansible_collections.paloaltonetworks.panos.plugins.modules.panos_device_group', _modlib_path=modlib_path),\n File "", line 226, in run_module\n File "", line 98, in _run_module_code\n File "", line 88, in _run_code\n File "/tmp/ansible_paloaltonetworks.panos.panos_device_group_payload_dyhih3b8/ansible_paloaltonetworks.panos.panos_device_group_payload.zip/ansible_collections/paloaltonetworks/panos/plugins/modules/panos_device_group.py", line 157, in \n File "/tmp/ansible_paloaltonetworks.panos.panos_device_group_payload_dyhih3b8/ansible_paloaltonetworks.panos.panos_device_group_payload.zip/ansible_collections/paloaltonetworks/panos/plugins/modules/panos_device_group.py", line 153, in main\n File "/tmp/ansible_paloaltonetworks.panos.panos_device_group_payload_dyhih3b8/ansible_paloaltonetworks.panos.panos_device_group_payload.zip/ansible_collections/paloaltonetworks/panos/plugins/module_utils/panos.py", line 516, in process\n File "/tmp/ansible_paloaltonetworks.panos.panos_device_group_payload_dyhih3b8/ansible_paloaltonetworks.panos.panos_device_group_payload.zip/ansible_collections/paloaltonetworks/panos/plugins/module_utils/panos.py", line 702, in apply_state\n File "/tmp/ansible_paloaltonetworks.panos.panos_device_group_payload_dyhih3b8/ansible_paloaltonetworks.panos.panos_device_group_payload.zip/ansible_collections/paloaltonetworks/panos/plugins/module_utils/panos.py", line 82, in eltostr\n File "/home/ansibleuser/.local/lib/python3.12/site-packages/panos/base.py", line 534, in element_str\n return ET.tostring(self.element(), encoding="utf-8")\n ^^^^^^^^^^^^^^\n File "/home/ansibleuser/.local/lib/python3.12/site-packages/panos/base.py", line 2615, in element\n self.xml_merge(ans, itertools.chain(*iterchain))\n File "/home/ansibleuser/.local/lib/python3.12/site-packages/panos/base.py", line 1699, in xml_merge\n for e in elements:\n File "/home/ansibleuser/.local/lib/python3.12/site-packages/panos/base.py", line 573, in _subelements\n e.append(child.element(comparable=comparable))\n ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\nTypeError: Firewall.element() got an unexpected keyword argument 'comparable'\n", "module_stdout": "", "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error", "rc": 1}

Expected behavior

Ansible should be able to run the command without any issues as the child or parent device group name is not changed.

Current behavior

Ansible is giving above mentioned error.

Possible solution

In the _subelements function , if I remove the "comparable=comparable" then everything works fine, I think element does not support that argument as error suggested.
e.append(child.element(comparable=comparable))

Steps to reproduce

  1. create sample playbook with following config:
- name: Palo Alto test
  hosts: palo
  connection: local

  collections:
    - paloaltonetworks.panos
  vars:
  device_groups:
    - group_name: "site_dg"
    - group_name: 'dev_dg'
      parent: 'site_dg'
  tasks: 
    - name: Create Panorama device groups
      paloaltonetworks.panos.panos_device_group:
        provider: '{{ provider }}'
        name: "{{ item.group_name}}"
        parent: "{{ item.parent | default(omit)}}"
      loop: "{{ device_groups }}"
  1. run the playbook , it should create both device groups in Panorama
  2. Add /register firewalls in dev_dg group
  3. run the playbook and it will fail with above error mentioned in the description.

Screenshots

Context

I was trying to re-run the ansible playbook and got this error.

Your Environment

Collection: paloaltonetworks.panos 2.21.4
Python: 3.12.3
Ansible: 2.16.3
PAN-OS Python Library & version:
pan-os-python 1.12.1
pan-python 0.17.0
pandevice 0.14.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions