Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 79 additions & 0 deletions parser_templates/cli/show_ip_ospf_neighbor.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
---

- name: show_ip_ospf_neighbor
parser_metadata:
version: 1.0
command: show ip ospf neighbor
network_os: ios

- name: match not active
register: not_active
pattern_match:
regex: ".+"
match_all: true

- name: set_vars ospf state not active
set_vars:
process_state: "not active"

- name: set_vars ospf state active
set_vars:
process_state: "active"
when: "not_active.0.matches | length > 0"

- name: match sections
register: context
pattern_match:
regex: "Neighbor.+"
match_all: yes
match_greedy: yes
when: process_state == 'active'

- name: match lines
register: lines
pattern_match:
regex: "^[0-9a-z.].+"
content: "{{ context.0 }}"
match_all: yes
match_greedy: yes
when: process_state == 'active'

- name: match neighbors
register: matched_neighbors
loop: "{{ lines }}"
pattern_match:
regex: "(?P<neighbor>^[0-9a-z.]+)\\s+(?P<pri>\\d)\\s+(?P<state>([A-Z]|.)+)/(?P<role>([A-Z]|.)+)\\s(?P<timer>[0-9][0-9]:[0-5][0-9]:[0-5][0-9])\\s(?P<ip>.+\\s)(?P<interface>[A-Z].+)"
content: "{{ item }}"
when: process_state == 'active'

- name: template ospf values
extend: cisco_ios
register: ospf
export: true
export_as: dict
json_template:
template:
- key: "process_state"
value: "{{ process_state }}"

- name: template ospf neighbor entries
extend: cisco_ios.ospf
register: neighbors
export: true
export_as: dict
loop: "{{ matched_neighbors }}"
when: process_state == 'active'
json_template:
template:
- key: "{{ item.ip | trim }}"
object:
- key: neighbor_id
value: "{{ item.neighbor | trim }}"
- key: state
value: "{{ item.state | trim }}"
- key: role
value: "{{ item.role | trim }}"
- key: timer
value: "{{ item.timer | trim}}"
- key: interface
value: "{{ item.interface | trim }}"
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

Neighbor ID Pri State Dead Time Address Interface
ansi06a1.redhat 0 FULL/ - 00:00:37 130.200.191.21 Tunnel821
ansi07a2.redhat 0 FULL/ - 00:00:32 25.131.8.25 Tunnel825
ansi06a1.redhat 0 FULL/ - 00:00:36 191.11.131.5 Tunnel85
41 changes: 41 additions & 0 deletions tests/parser_templates/cli/show_ip_ospf_neighbor/main.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
---

### OSPF not active

- name: not active - parse `show ip ospf neighbor`
command_parser:
file: "{{ playbook_dir }}/../parser_templates/cli/show_ip_ospf_neighbor.yaml"
content: "{{ lookup('file', '{{ playbook_dir }}/parser_templates/cli/show_ip_ospf_neighbor/ospf_not_active.txt') }}"
register: result

- name: not active - test `show ip ospf neighbor` parser
assert:
that:
- cisco_ios.ospf['process_state'] == 'not active'

- name: clear facts
meta: clear_facts

### IOS 15.4(3r)M1.txt

- name: 15.4(3r)M1.txt - parse `show ip ospf neighbor`
command_parser:
file: "{{ playbook_dir }}/../parser_templates/cli/show_ip_ospf_neighbor.yaml"
content: "{{ lookup('file', '{{ playbook_dir }}/parser_templates/cli/show_ip_ospf_neighbor/15.4(3r)M1.txt') }}"
register: result

- name: 15.4(3r)M1.txt - test `show ip ospf neighbor` parser
assert:
that:
- "'130.200.191.21' in cisco_ios.ospf['neighbors']"
- cisco_ios.ospf['neighbors']['130.200.191.21']['neighbor_id'] == 'ansi06a1.redhat'
- cisco_ios.ospf['neighbors']['130.200.191.21']['state'] == 'FULL'
- cisco_ios.ospf['neighbors']['130.200.191.21']['role'] == '-'
- cisco_ios.ospf['neighbors']['130.200.191.21']['timer'] == '00:00:37'
- cisco_ios.ospf['neighbors']['130.200.191.21']['interface'] == 'Tunnel821'

### Done

- name: all tests complete
debug:
msg: "All tests for `show ip ospf summary` passed"
Empty file.
24 changes: 17 additions & 7 deletions tests/test_parser_templates.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,22 @@
vars:
bgp: "{{ cisco_ios['vrf']['DEFAULT']['protocols']['bgp'] }}"

- name: Include tests for `show ip vrf detail`
include_tasks: parser_templates/cli/show_ip_vrf_detail/main.yaml
vars:
vrfs: "{{ cisco_ios['vrf'] }}"
#- name: Include tests for `show ip bgp summary`
# include_tasks: parser_templates/cli/show_ip_bgp_summary/main.yaml
# vars:
# bgp: "{{ cisco_ios['vrf']['DEFAULT']['protocols']['bgp'] }}"

#- name: Include tests for `show ip vrf detail`
# include_tasks: parser_templates/cli/show_ip_vrf_detail/main.yaml
# vars:
# vrfs: "{{ cisco_ios['vrf'] }}"

- name: Include tests for `show version`
include_tasks: parser_templates/cli/show_version/main.yaml
- name: Include tests for `show ip ospf neighbor`
include_tasks: parser_templates/cli/show_ip_ospf_neighbor/main.yaml
vars:
system: "{{ cisco_ios['system'] }}"
system: "{{ cisco_ios['vrf']['DEFAULT']['protocols']['ospf'] }}"

#- name: Include tests for `show version`
# include_tasks: parser_templates/cli/show_version/main.yaml
# vars:
# system: "{{ cisco_ios['system'] }}"
7 changes: 7 additions & 0 deletions vars/get_facts_command_map.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,10 @@
- all
- vrf
- routing

- command: show ip ospf neighbor
parser: show_ip_ospf_neighbor.yaml
groups:
- all
- ospf
- routing