Skip to content

Commit 0d8bef6

Browse files
committed
add parser for cdp and interfaces
1 parent ee8cac7 commit 0d8bef6

File tree

2 files changed

+123
-0
lines changed

2 files changed

+123
-0
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
---
2+
- name: match cdp sections
3+
pattern_match:
4+
regex: "^----------------------------------------"
5+
match_all: yes
6+
match_greedy: yes
7+
register: context
8+
9+
- name: match cpd values
10+
pattern_group:
11+
- name: match name
12+
pattern_match:
13+
regex: "Device ID:(|\\s)(.+)\\("
14+
content: "{{ item }}"
15+
register: device_id
16+
17+
- name: match interface
18+
pattern_match:
19+
regex: "Interface: (.+), Port ID \\(outgoing port\\): (.+)"
20+
content: "{{ item }}"
21+
register: interface
22+
23+
loop: "{{ context }}"
24+
register: values
25+
26+
- name: build cdp template
27+
json_template:
28+
template:
29+
- key: "{{ item.device_id.matches.1 }}"
30+
object:
31+
- key: local_port
32+
value: "{{ item.interface.matches.0 }}"
33+
- key: remote_port
34+
value: "{{ item.interface.matches.1}}"
35+
loop: "{{ values }}"
36+
register: neighbors
37+
export: yes
38+
export_as: dict
39+
extend: cisco_nxos
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
---
2+
- name: match interface sections
3+
pattern_match:
4+
regex: "^\\S+ is (up|down)"
5+
match_all: yes
6+
match_greedy: yes
7+
register: context
8+
9+
- name: match interface values
10+
pattern_group:
11+
- name: match name
12+
pattern_match:
13+
regex: "^(.+) is (\\w+)"
14+
content: "{{ item }}"
15+
register: name
16+
17+
- name: match admin state
18+
pattern_match:
19+
regex: "admin state is (\\S+)"
20+
content: "{{ item }}"
21+
register: admin_state
22+
23+
- name: match mac address
24+
pattern_match:
25+
regex: "Hardware: Ethernet, address: ([\\d|\\w]{4}.[\\d|\\w]{4}.[\\d|\\w]{4})"
26+
content: "{{ item }}"
27+
register: mac_addr
28+
29+
- name: match description value
30+
pattern_match:
31+
regex: "Description: (.*)"
32+
content: "{{ item }}"
33+
register: description
34+
35+
- name: match mtu value
36+
pattern_match:
37+
regex: "MTU (\\d+)"
38+
content: "{{ item }}"
39+
register: mtu
40+
41+
- name: match ipv4 address
42+
pattern_match:
43+
regex: "Internet Address is (.+)"
44+
content: "{{ item }}"
45+
register: ipv4addr
46+
47+
- name: match port mode
48+
pattern_match:
49+
regex: "Port mode is (.+)"
50+
content: "{{ item }}"
51+
register: port_mode
52+
53+
loop: "{{ context }}"
54+
register: values
55+
56+
- name: build interface template
57+
json_template:
58+
template:
59+
- key: "{{ item.name.matches.0 }}"
60+
object:
61+
- key: oper_status
62+
value: "{{ item.name.matches.1 }}"
63+
- key: admin_status
64+
value: "{{ item.admin_state.matches.0}}"
65+
- key: mac_address
66+
value: "{{ item.mac_addr.matches.0 }}"
67+
- key: ipv4
68+
object:
69+
- key: address
70+
value: "{{ item.ipv4addr.matches.0.split('/')[0] }}"
71+
- key: masklen
72+
value: "{{ item.ipv4addr.matches.0.split('/')[1] }}"
73+
when: item.ipv4addr.matches
74+
- key: description
75+
value: "{{ item.description.matches.0 }}"
76+
- key: mtu
77+
value: "{{ item.mtu.matches.0 }}"
78+
- key: port_mode
79+
value: "{{ item.port_mode.matches.0}}"
80+
loop: "{{ values }}"
81+
register: interfaces
82+
export: yes
83+
export_as: dict
84+
extend: cisco_nxos

0 commit comments

Comments
 (0)