-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathxml_interface_rpc.yaml
78 lines (66 loc) · 2.08 KB
/
xml_interface_rpc.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
---
- name: Get Device Interfaces
hosts: vmx1
roles:
- Juniper.junos
connection: local
gather_facts: no
vars:
- name: Set authorized key took from file
authorized_key:
user: fortinet
state: present
key: "{{ lookup('file', '/home/mis/.ssh/id_rsa.pub') }}"
# vars_prompt:
# - name: username
# propmpt: Junos username
# private: no
# - name: password
# prompt: Junos password
# private: yes
tasks:
- name: gathering info from device
juniper_junos_rpc:
rpcs:
- get-interface-information
formats: xml # options xml,json, text
# dest_dir: '.'
# return_output: no
# kwargs:
# detail: True
# interface_name: ge-0/0/0
# junos_get_facts: host={{ inventory_hostname }}
# juniper_junos_rpc:
# rpcs:
# - get-system-uptime-information
provider:
host: "{{ ansible_host }}"
# user: "{{ username }}"
# password: "{{ password }}"
# port: 22 #if commented out use NETCONF default port 830
register: interfaces
- name: query interface name
xml:
xmlstring: "{{ interfaces.stdout }}"
xpath: //physical-interface/logical-interface/name
content: text
register: if_name
- name: query interface IP
xml:
xmlstring: "{{ interfaces.stdout }}"
xpath: //logical-interface/address-family[address-family-name='inet']/interface-address/ifa-local
content: text
register: ip_addr
- name: show query results1
debug:
msg: "{{ if_name.matches | map(attribute='name') | list }}; {{ ip_addr.matches | map(attribute='ifa-local') | list }}"
- name: show query results2
debug:
msg: "{{ ip_addr.matches }}"
# map('lower') | select('match','lo0') | list
# var: if_name.matches[0]['name'], ip_addr.matches[0]['ifa-local']
# var: uptime['stdout_lines'][6]
verbosity: 0
# when: uptime.parsed_output['system-uptime-information'] is defined
# - debug:
# var: ansible_host