PaloAltoNetworks/pan-os-ansible

paloaltonetworks.panos.panos_template issue on second run

aink99 opened this issue · 1 comments

Describe the bug

When creating a new template and attaching an interface you get this error when you run the playbook for a second time. First execution is fine.

TASK [Create "TEST-TPL-BUG" template] ****************************************************************************************************************************************************
fatal: [192.168.0.11]: FAILED! => {"changed": false, "msg": "Failed update mode: Could not get schema node for xpath /config/devices/entry[@name='localhost.localdomain']/template/entry[@name='TEST-TPL-BUG']/mode\n"}

Expected behavior

This task should just return ok

Current behavior

PLAY [Configure Panorama] ****************************************************************************************************************************************************************

TASK [Print Ansible version & Fail Deploy If Inventory Is Empty] *************************************************************************************************************************
ok: [192.168.0.11] => {
"msg": "Ansible version is 2.15.9"
}

TASK [Get facts] *************************************************************************************************************************************************************************
ok: [192.168.0.11]

TASK [Display] ***************************************************************************************************************************************************************************
ok: [192.168.0.11] => {
"msg": [
"All: {'net_gather_subset': ['system', 'ha'], 'net_hostname': 'vm-anoramaqas', 'net_model': 'Panorama', 'net_serial': '00000002', 'net_version': '10.2.3', 'net_uptime': '88 days, 0:36:57', 'net_multivsys': None, 'net_uncommitted_changes': True, 'net_full_commit_required': False, 'net_ha_enabled': False, 'net_ha_localmode': 'standalone', 'net_ha_localstate': 'active', 'discovered_interpreter_python': '/usr/bin/python3'}"
]
}

TASK [Setting template name] *************************************************************************************************************************************************************
ok: [192.168.0.11]

TASK [Check if template "TEST-TPL-BUG" exists] *******************************************************************************************************************************************
ok: [192.168.0.11]

TASK [Print template existence] **********************************************************************************************************************************************************
ok: [192.168.0.11] => {
"msg": {
"changed": false,
"failed": false,
"gathered": [
{
"default_vsys": "vsys1",
"description": null,
"devices": null,
"mode": null,
"multi_vsys": null,
"name": "TEST-TPL-BUG",
"vpn_disable_mode": null
}
],
"gathered_xml": [
"\n<entry name="TEST-TPL-BUG">\n\t\n\t\tvsys1\n\t\n\t\n\t\t\n\t\t\t<entry name="localhost.localdomain">\n\t\t\t\t\n\t\t\t\t\t<entry name="vsys1">\n\t\t\t\t\t\t\n\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t\tethernet1/2\n\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\n\t\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\n\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t\t\n\t\t\t\t\t\t\t<entry name="ethernet1/2">\n\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\n\t\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t\t<entry name="none">\n\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\tethernet1/2\n\t\t\t\t\t\t\t\n\t\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\n\t\t\t\n\t\t\n\t\n\n"
]
}
}

TASK [Create "TEST-TPL-BUG" template] ****************************************************************************************************************************************************
fatal: [192.168.0.11]: FAILED! => {"changed": false, "msg": "Failed update mode: Could not get schema node for xpath /config/devices/entry[@name='localhost.localdomain']/template/entry[@name='TEST-TPL-BUG']/mode\n"}

PLAY RECAP *******************************************************************************************************************************************************************************
192.168.0.11 : ok=6 changed=0 unreachable=0 failed=1 skipped=0 rescued=0 ignored=0

Steps to reproduce

# Configure Panorama
- name: 'Configure Panorama'
  hosts: panorama
  gather_facts: false
  connection: local
  become: false

  vars:
    device:
      ip_address: "{{ ansible_host }}"
      username: seb
      api_key: "{{ lookup('env','API_KEY') }}"
     
  tasks:
    - name: Print Ansible version & Fail Deploy If Inventory Is Empty
      ansible.builtin.debug:
        msg: "Ansible version is {{ ansible_version.full }}"

    # - name: Print Ansible Pipeline Variables
    #   debug:
    #     msg: "Environment is {{ environment_id }}"

    - name: Get facts
      connection: local
      paloaltonetworks.panos.panos_facts:
        # api_key: "{{ panorama_api_key }}"
        # ip_address: "{{ ansible_host }}"
        # username: "ansible"
        provider: "{{ device }}"

    - name: Display
      ansible.builtin.debug:
        msg:
          - "All: {{ ansible_facts }}"

    - name: Setting template name
      ansible.builtin.set_fact:
        template_name: TEST-TPL-BUG
      tags:
        - Template
        - TEST-TPL-BUG

    # # Check if the template {{ template_name}} exists,
    # # due to a known bug where attached interfaces may cause a failure.
    - name: Check if template "{{ template_name}}" exists
      paloaltonetworks.panos.panos_template:
        provider: "{{ device }}"
        name: "{{ template_name }}"
        gathered_filter: name matches-regex ^{{ template_name }}$
        state: gathered
      ignore_errors: true
      register: template_exist
      tags:
        - Template
        - TEST-TPL-BUG

    # Print the result of the template existence check.
    - name: Print template existence
      ansible.builtin.debug:
        msg: "{{ template_exist }}"
      tags:
        - Template
        - TEST-TPL-BUG

    # Create the {{ template_name}} template if it doesn't exist
    # to avoid potential errors caused by attached interfaces.
    - name: Create "{{ template_name }}" template
      #when: not template_exist.gathered
      paloaltonetworks.panos.panos_template:
        provider: "{{ device }}"
        name: "{{ template_name }}"
        #description: "{{ template_name }}"
      ignore_errors: false
      tags:
        - Template
        - TEST-TPL-BUG

    - name: Ethernet1/2  for "{{ template_name }}"
      paloaltonetworks.panos.panos_interface:
        provider: "{{ device }}"
        if_name: ethernet1/2
        mode: layer3
        vr_name: none
        enable_dhcp: false
        template: "{{ template_name }}"
      tags:
        - Template
        - TEST-TPL-BUG

Context

This prevent me from upating zones and interfraces linked to this template.

Your Environment

  • Collection: ansible-galaxy collection install paloaltonetworks.panos:2.19.1
  • Python: Python 3.9.18
  • Ansible: 2.15.9
  • PAN-OS
    pan-os-python 1.8.0
    pan-python 0.17.0
    panos-upgrade-assurance 0.3.0
    xmltodict 0.12.0
  • Panorama: 10.2.3

Hello @aink99 !

Could you please also put here a run (with -vvv) of the original run of the playbook when you create the template?