Ansible panos_facts Config Sub Set

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements

Ansible panos_facts Config Sub Set

L0 Member

Good afternoon team,

 

I need to obtain values such as the Panorama server IP from a firewall to accomplish a project using Ansible and the paloaltonetworks.panos 2.2.0 collection. The panos_facts module with the config subset specified outputs what appears to be xml. What was this outputs intended use?  Was it intended to be parsed for registering variables or are we supposed to use the panos_op module to grab any parts of the config we require for variables?  I can find no examples of using this output realistically.   There are of course many ways to skin the cat so I'm just wondering if anyone is using the panos_facts/gather_subset: config output to do the job?


-  panos_facts:
     provider: '{{ provider }}'
     gather_subset: ['config']
   register: panfacts_config

 

Thanks all,

Nicolas

1 accepted solution

Accepted Solutions

L0 Member

Circling back here. The panos_op module can be a bad time in trying to parse the output for the variable you want. What I ended up doing was gathering the facts with the panos_facts config subset and then parsing the xml for the info I needed. Find an example below.

 

- name: copy panfacts into a file
  template:
   src: /etc/ansible/cp_sucks_prod/palo_show_role/templates/panfacts.j2
   dest: /etc/ansible/cp_sucks_prod/palo_show_role/templates/cp_sucks_prod_panfacts.xml

 

- name: Get panorama IP from the xml output
  community.general.xml:
   path: /etc/ansible/cp_sucks_prod/palo_show_role/templates/cp_sucks_prod_panfacts.xml
   xpath: /config/devices/entry[@name='localhost.localdomain']/deviceconfig/system/panorama-server
   content: text
  register: panorama_server_var

 

- name: print panorama var parsed from xml
  debug: var=item.value
  loop: "{{panorama_server_var.matches.0|dict2items}}"

 

- name: set Panorama IP address variable.
  set_fact:
    panorama_IP: "{{item.value}}"
  loop: "{{panorama_server_var.matches.0|dict2items}}"

View solution in original post

1 REPLY 1

L0 Member

Circling back here. The panos_op module can be a bad time in trying to parse the output for the variable you want. What I ended up doing was gathering the facts with the panos_facts config subset and then parsing the xml for the info I needed. Find an example below.

 

- name: copy panfacts into a file
  template:
   src: /etc/ansible/cp_sucks_prod/palo_show_role/templates/panfacts.j2
   dest: /etc/ansible/cp_sucks_prod/palo_show_role/templates/cp_sucks_prod_panfacts.xml

 

- name: Get panorama IP from the xml output
  community.general.xml:
   path: /etc/ansible/cp_sucks_prod/palo_show_role/templates/cp_sucks_prod_panfacts.xml
   xpath: /config/devices/entry[@name='localhost.localdomain']/deviceconfig/system/panorama-server
   content: text
  register: panorama_server_var

 

- name: print panorama var parsed from xml
  debug: var=item.value
  loop: "{{panorama_server_var.matches.0|dict2items}}"

 

- name: set Panorama IP address variable.
  set_fact:
    panorama_IP: "{{item.value}}"
  loop: "{{panorama_server_var.matches.0|dict2items}}"

  • 1 accepted solution
  • 2652 Views
  • 1 replies
  • 0 Likes
Like what you see?

Show your appreciation!

Click Like if a post is helpful to you or if you just want to show your support.

Click Accept as Solution to acknowledge that the answer to your question has been provided.

The button appears next to the replies on topics you’ve started. The member who gave the solution and all future visitors to this topic will appreciate it!

These simple actions take just seconds of your time, but go a long way in showing appreciation for community members and the LIVEcommunity as a whole!

The LIVEcommunity thanks you for your participation!