Skip to content

Instantly share code, notes, and snippets.

@jeffbrl
Last active February 8, 2017 17:32
Show Gist options
  • Select an option

  • Save jeffbrl/6d7ae46e0567f95d0c66aa8811e57cc1 to your computer and use it in GitHub Desktop.

Select an option

Save jeffbrl/6d7ae46e0567f95d0c66aa8811e57cc1 to your computer and use it in GitHub Desktop.
- name: Get primary lo0 address
hosts: all
connection: local
gather_facts: no
roles:
- Juniper.junos
- cmprescott.xml
vars:
temp_dir: /tmp
USER: jeffl
PASSWORD: pass123
tasks:
- name: create temporary filename
shell: mktemp "{{ temp_dir }}"/`date +"%Y%m%d%d%m"`"_{{ inventory_hostname }}".XXXXX.xml
register: temp_file
- name: Execute get_config RPC
junos_rpc:
host={{ inventory_hostname }}
user={{ USER }}
port=22
passwd={{ PASSWORD }}
rpc=get_config
logfile=logs/{{ inventory_hostname }}_cli.log
dest="{{ temp_file.stdout }}"
format=xml
filter_xml="<configuration><interfaces><interface><name>lo0</name></interface></interfaces></configuration>"
- name: Parse XML
xml:
file={{ temp_file.stdout }}
xpath=//unit[name='0']/family/inet/address/primary/preceding-sibling::name
content=text
register: loopback_address_match
failed_when: loopback_address_match['matches'] is not defined
- name: Set fact
set_fact:
loopback: "{{ loopback_address_match['matches'][0]['name'] }}"
- name: Print fact
debug:
var: loopback
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment