diff --git a/ansible.cfg b/ansible.cfg new file mode 100644 index 0000000..116401d --- /dev/null +++ b/ansible.cfg @@ -0,0 +1,5 @@ +[defaults] + +filter_plugins = filter_plugins + + diff --git a/filter_plugins/ios.py b/filter_plugins/ios.py index 6fda4db..d0f31f0 100644 --- a/filter_plugins/ios.py +++ b/filter_plugins/ios.py @@ -16,6 +16,14 @@ } +ROUTING_PROTOCOLS = {'L': 'local', 'C': 'connected', 'S': 'static', 'R': 'rip', 'M': 'mobile', 'B': 'bgp', 'D': 'eigrp', 'EX': 'eigrp external', 'O': 'ospf', + 'IA': 'ospf inter area', 'N1': 'ospf nssa external type 1', 'N2': 'ospf nssa external type 2', 'E1': 'ospf external type 1', + 'E2': 'ospf external type 2', 'i': 'is-is', 'su': 'is-is summary', 'L1': 'is-is level-1', 'L2': 'is-is level-2', + 'ia': 'is-is inter area', '*': 'candidate default', 'U': 'per-user static route', 'o': 'odr', + 'P': 'periodic downloaded static route', 'H': 'nhrp', 'l': 'lisp', 'a': 'application route', + '+': 'replicated route', '%': 'next hop override'} + + def expand_interface_name(name): match = re.match('([a-zA-Z]*)', name) if match and match.group(1) in INTERFACE_NAMES: @@ -24,11 +32,20 @@ def expand_interface_name(name): return name +def expand_routing_protocol_name(name): + match = re.match(r'([\S]*)', name) + if match and match.group(1) in ROUTING_PROTOCOLS: + matched = match.group(1) + name = name.replace(matched, ROUTING_PROTOCOLS[matched]) + return name + + class FilterModule(object): """Filters for working with output from network devices""" filter_map = { - 'expand_interface_name': expand_interface_name + 'expand_interface_name': expand_interface_name, + 'expand_routing_protocol_name': expand_routing_protocol_name } def filters(self): diff --git a/parser_templates/cli/show_ip_route.yaml b/parser_templates/cli/show_ip_route.yaml new file mode 100644 index 0000000..c8e1051 --- /dev/null +++ b/parser_templates/cli/show_ip_route.yaml @@ -0,0 +1,63 @@ +--- +- name: show_ip_route + parser_metadata: + version: 1.0 + command: "show ip route" + network_os: ios + +# Caveat: This parser only returns the first next hop, for prefixes with multiple possible destinations. + +- name: match route section + export: true + register: global_section + pattern_match: + regex: "^Gateway of last resort is (([0-9.])+)" + match_all: true + match_greedy: true + +- name: match vrf section values + loop: "{{ global_section }}" + register: route_section_values + pattern_group: + - name: match default route + pattern_match: + regex: "^Gateway of last resort is (([0-9.])+)" + content: "{{ item }}" + register: default_route + + - name: match prefixes + pattern_match: + regex: "^(?PL|C|S|R|M|B|D|EX|O|IA|N1|N2|E1|E2|i|su|L1|L2|ia|U|o|P|H|l|a)(?P\\s|\\*|\\+\\|\\%)\\s+(?P\\d{1,3}.\\d{1,3}.\\d{1,3}.\\d{1,3})(?P|\\/\\d{,2})(?:|\\s+\\[(?P\\d+/\\d+)\\]) (?Pis directly connected, (?P\\S+$)|is a summary, \\S+, (?P\\S+$)|via (?P\\S+)(?:, |$))" + content: "{{ item }}" + match_all: true + register: match_prefixes + +- name: template vrf-instances + register: vrf + extend: cisco_ios + export: true + export_as: dict + loop: "{{ route_section_values }}" + loop_control: + loop_var: route_item + json_template: + template: + - key: DEFAULT + object: + - key: default_route + value: "{{ route_item.default_route.matches.0 }}" + - key: routing_table + repeat_for: "{{ route_item.match_prefixes }}" + repeat_var: nested_item + object: "{{ + { + nested_item.prefix+nested_item.mask: + { + 'subnet': nested_item.prefix, + 'mask': nested_item.mask, + 'protocol': nested_item.prot, + 'dist_metric': nested_item.metric, + 'next_hop': ([nested_item.next_hop_nbr]+[nested_item.next_hop_int, nested_item.next_hop_int_sum]) | reject('equalto', '') | list + } + } + }}" diff --git a/parser_templates/cli/show_ip_route_vrf_all.yaml b/parser_templates/cli/show_ip_route_vrf_all.yaml new file mode 100644 index 0000000..c4098c6 --- /dev/null +++ b/parser_templates/cli/show_ip_route_vrf_all.yaml @@ -0,0 +1,71 @@ +--- +- name: show_ip_route_vrf_all + parser_metadata: + version: 1.0 + command: "show ip route vrf *" + network_os: ios + +# Caveat: This parser only returns the first next hop, for prefixes with multiple possible destinations. + +- name: match vrf section + export: true + register: vrf_section + pattern_match: + regex: "^Routing Table: (\\S+)" + match_all: true + match_greedy: true + +- name: match vrf section values + loop: "{{ vrf_section }}" + register: vrf_section_values + pattern_group: + - name: match name + pattern_match: + regex: "^Routing Table: (\\S+)" + content: "{{ item }}" + register: name + + - name: match default route + pattern_match: + regex: "^Gateway of last resort is (([0-9.]+)|(not set))" + content: "{{ item }}" + register: default_route + + - name: match prefixes + pattern_match: + regex: "^(?PL|C|S|R|M|B|D|EX|O|IA|N1|N2|E1|E2|i|su|L1|L2|ia|U|o|P|H|l|a)(?P\\s|\\*|\\+\\|\\%)\\s+(?P\\d{1,3}.\\d{1,3}.\\d{1,3}.\\d{1,3})(?P|\\/\\d{,2})(?:|\\s+\\[(?P\\d+/\\d+)\\]) (?Pis directly connected, (?P\\S+$)|is a summary, \\S+, (?P\\S+$)|via (?P\\S+)(?:, |$))" + content: "{{ item }}" + match_all: true + register: match_prefixes + +- name: template vrf-instances + register: vrf + extend: cisco_ios + export: true + export_as: dict + loop: "{{ vrf_section_values }}" + loop_control: + loop_var: vrf_item + json_template: + template: + - key: "{{ vrf_item.name.matches.0 }}" + object: + - key: name + value: "{{ vrf_item.name.matches.0 }}" + - key: default_route + value: "{{ vrf_item.default_route.matches.0 }}" + - key: routing_table + repeat_for: "{{ vrf_item.match_prefixes }}" + repeat_var: nested_item + object: "{{ + { + nested_item.prefix+nested_item.mask: + { + 'subnet': nested_item.prefix, + 'mask': nested_item.mask, + 'protocol': nested_item.prot | expand_routing_protocol_name, + 'dist_metric': nested_item.metric, + 'next_hop': ([nested_item.next_hop_nbr]+[nested_item.next_hop_int, nested_item.next_hop_int_sum]) | reject('equalto', '') | list + } + } + }}" diff --git a/tests/parser_templates/cli/show_ip_route/03.14.00.S.txt b/tests/parser_templates/cli/show_ip_route/03.14.00.S.txt new file mode 100644 index 0000000..1fd46ea --- /dev/null +++ b/tests/parser_templates/cli/show_ip_route/03.14.00.S.txt @@ -0,0 +1,22 @@ +Codes: L - local, C - connected, S - static, R - RIP, M - mobile, B - BGP + D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area + N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2 + E1 - OSPF external type 1, E2 - OSPF external type 2 + i - IS-IS, su - IS-IS summary, L1 - IS-IS level-1, L2 - IS-IS level-2 + ia - IS-IS inter area, * - candidate default, U - per-user static route + o - ODR, P - periodic downloaded static route, H - NHRP, l - LISP + a - application route + + - replicated route, % - next hop override + +Gateway of last resort is 10.25.25.1 to network 0.0.0.0 + +B* 0.0.0.0/0 [200/0] via 10.25.25.1, 08:12:34 + 1.0.0.0/29 is subnetted, 3 subnets +B 1.1.2.0 [200/0] via 10.25.253.2, 08:12:34 + 10.0.0.0/8 is variably subnetted, 417 subnets, 10 masks +B 10.55.134.252/30 [200/0] via 10.25.25.1, 08:12:34 +C 10.251.253.0/24 is directly connected, GigabitEthernet0/0/2.1701 +L 10.251.253.1/32 is directly connected, GigabitEthernet0/0/2.1701 + 10.28.0.0/28 is subnetted, 2 subnets +B 10.28.194.0 [200/0] via 10.25.25.1, 08:12:49 +B 10.28.194.16 [200/0] via 10.25.25.1, 08:12:49 diff --git a/tests/parser_templates/cli/show_ip_route/12.2(33)SXH1.txt b/tests/parser_templates/cli/show_ip_route/12.2(33)SXH1.txt new file mode 100644 index 0000000..9871065 --- /dev/null +++ b/tests/parser_templates/cli/show_ip_route/12.2(33)SXH1.txt @@ -0,0 +1,32 @@ +Codes: L - local, C - connected, S - static, R - RIP, M - mobile, B - BGP + D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area + N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2 + E1 - OSPF external type 1, E2 - OSPF external type 2 + i - IS-IS, su - IS-IS summary, L1 - IS-IS level-1, L2 - IS-IS level-2 + ia - IS-IS inter area, * - candidate default, U - per-user static route + o - ODR, P - periodic downloaded static route, H - NHRP, l - LISP + a - application route + + - replicated route, % - next hop override, p - overrides from PfR + +Gateway of last resort is 10.31.0.106 to network 0.0.0.0 + +B* 0.0.0.0/0 [20/0] via 10.31.0.106, 6d17h + 10.0.0.0/8 is variably subnetted, 2 subnets, 2 masks +C 10.242.61.0/24 is directly connected, GigabitEthernet0/0/1.11 +L 10.242.61.1/32 is directly connected, GigabitEthernet0/0/1.11 + 10.19.0.0/32 is subnetted, 5 subnets +B 10.19.50.1 [20/0] via 10.31.0.106, 6d17h +B 10.19.50.2 [20/0] via 10.31.0.106, 6d17h +B 10.19.50.3 [20/0] via 10.31.0.106, 6d17h +B 10.19.50.129 [20/0] via 10.31.0.106, 6d17h +B 10.19.50.130 [20/0] via 10.31.0.106, 6d17h + 10.29.0.0/16 is variably subnetted, 6 subnets, 2 masks +B 10.29.160.26/31 [200/0], 6d17h, Null0 +C 10.29.160.26/32 is directly connected, Loopback3 +C 10.29.160.27/32 is directly connected, Loopback4 +B 10.29.192.26/31 [200/0], 6d17h, Null0 +C 10.29.192.26/32 is directly connected, Loopback1 +C 10.29.192.27/32 is directly connected, Loopback2 + 10.31.0.0/16 is variably subnetted, 2 subnets, 2 masks +C 10.31.0.104/29 is directly connected, GigabitEthernet0/0/0 +L 10.31.0.105/32 is directly connected, GigabitEthernet0/0/0 diff --git a/tests/parser_templates/cli/show_ip_route/main.yaml b/tests/parser_templates/cli/show_ip_route/main.yaml new file mode 100644 index 0000000..af6c500 --- /dev/null +++ b/tests/parser_templates/cli/show_ip_route/main.yaml @@ -0,0 +1,34 @@ +--- +### IOS 12.2(33)SXH1 + +- name: 12.2(33)SXH1 - parse `show ip route` + command_parser: + file: "{{ playbook_dir }}/../parser_templates/cli/show_ip_route.yaml" + content: "{{ lookup('file', '{{ playbook_dir }}/parser_templates/cli/show_ip_route/12.2(33)SXH1.txt') }}" + register: result + +- name: 12.2(33)SXH7 - test `show ip route` + assert: + that: + - "'DEFAULT' in vrfs" + - "'routing_table' in vrfs.DEFAULT" + +### IOS-XE 03.14.00.S + +- name: 03.14.00.S - parse `show ip route` + command_parser: + file: "{{ playbook_dir }}/../parser_templates/cli/show_ip_route.yaml" + content: "{{ lookup('file', '{{ playbook_dir }}/parser_templates/cli/show_ip_route/03.14.00.S.txt') }}" + register: result + +- name: 03.14.00.S - test `show ip route` + assert: + that: + - "'routing_table' in vrfs.DEFAULT" + - vrfs.DEFAULT['routing_table']['0.0.0.0/0']['protocol'] == 'B' + +### Done + +- name: all tests complete + debug: + msg: "All tests for `show ip route *` passed" diff --git a/tests/parser_templates/cli/show_ip_route_vrf_all/03.14.00.S.txt b/tests/parser_templates/cli/show_ip_route_vrf_all/03.14.00.S.txt new file mode 100644 index 0000000..a038961 --- /dev/null +++ b/tests/parser_templates/cli/show_ip_route_vrf_all/03.14.00.S.txt @@ -0,0 +1,102 @@ +Codes: L - local, C - connected, S - static, R - RIP, M - mobile, B - BGP + D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area + N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2 + E1 - OSPF external type 1, E2 - OSPF external type 2 + i - IS-IS, su - IS-IS summary, L1 - IS-IS level-1, L2 - IS-IS level-2 + ia - IS-IS inter area, * - candidate default, U - per-user static route + o - ODR, P - periodic downloaded static route, H - NHRP, l - LISP + a - application route + + - replicated route, % - next hop override + +Gateway of last resort is 10.25.25.1 to network 0.0.0.0 + +B* 0.0.0.0/0 [200/0] via 10.25.25.1, 08:12:34 + 1.0.0.0/29 is subnetted, 3 subnets +B 1.1.2.0 [200/0] via 10.25.253.2, 08:12:34 + 10.0.0.0/8 is variably subnetted, 417 subnets, 10 masks +B 10.55.134.252/30 [200/0] via 10.25.25.1, 08:12:34 +C 10.251.253.0/24 is directly connected, GigabitEthernet0/0/2.1701 +L 10.251.253.1/32 is directly connected, GigabitEthernet0/0/2.1701 + 10.28.0.0/28 is subnetted, 2 subnets +B 10.28.194.0 [200/0] via 10.25.25.1, 08:12:49 +B 10.28.194.16 [200/0] via 10.25.25.1, 08:12:49 + +Routing Table: Mgmt-intf +Codes: L - local, C - connected, S - static, R - RIP, M - mobile, B - BGP + D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area + N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2 + E1 - OSPF external type 1, E2 - OSPF external type 2 + i - IS-IS, su - IS-IS summary, L1 - IS-IS level-1, L2 - IS-IS level-2 + ia - IS-IS inter area, * - candidate default, U - per-user static route + o - ODR, P - periodic downloaded static route, H - NHRP, l - LISP + a - application route + + - replicated route, % - next hop override + +Gateway of last resort is not set + +Routing Table: Def +Codes: L - local, C - connected, S - static, R - RIP, M - mobile, B - BGP + D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area + N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2 + E1 - OSPF external type 1, E2 - OSPF external type 2 + i - IS-IS, su - IS-IS summary, L1 - IS-IS level-1, L2 - IS-IS level-2 + ia - IS-IS inter area, * - candidate default, U - per-user static route + o - ODR, P - periodic downloaded static route, H - NHRP, l - LISP + a - application route + + - replicated route, % - next hop override + +Gateway of last resort is 10.28.130.255 to network 0.0.0.0 + +D* 0.0.0.0/0 [90/25605120] via 10.28.130.255, 08:13:19, Tunnel20 + 10.0.0.0/8 is variably subnetted, 2 subnets, 2 masks +C 10.4.6.0/21 is directly connected, GigabitEthernet0/0/1.211 +L 10.4.6.2/32 is directly connected, GigabitEthernet0/0/1.211 + 10.28.0.0/16 is variably subnetted, 3 subnets, 2 masks +C 10.28.128.0/20 is directly connected, Tunnel20 +L 10.28.128.8/32 is directly connected, Tunnel20 +D 10.28.160.0/20 + [90/25607936] via 10.4.6.3, 08:12:14, GigabitEthernet0/0/1.211 + 10.18.15.0/24 is variably subnetted, 3 subnets, 3 masks +D 10.18.15.32/27 is a summary, 08:15:24, Null0 +C 10.18.15.32/30 is directly connected, GigabitEthernet0/0/2.101 +L 10.18.15.33/32 is directly connected, GigabitEthernet0/0/2.101 + +Routing Table: Yzzz0-1-9 +Codes: L - local, C - connected, S - static, R - RIP, M - mobile, B - BGP + D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area + N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2 + E1 - OSPF external type 1, E2 - OSPF external type 2 + i - IS-IS, su - IS-IS summary, L1 - IS-IS level-1, L2 - IS-IS level-2 + ia - IS-IS inter area, * - candidate default, U - per-user static route + o - ODR, P - periodic downloaded static route, H - NHRP, l - LISP + a - application route + + - replicated route, % - next hop override + +Gateway of last resort is 10.28.130.0 to network 0.0.0.0 + +D* 0.0.0.0/0 [90/25605120] via 10.16.130.0, 1w2d, Tunnel20 + 10.0.0.0/21 is subnetted, 1 subnets +O 10.21.232.0 + [110/20] via 10.18.80..230, 7w0d, GigabitEthernet0/0/1.102 + 10.16.0.0/16 is variably subnetted, 3 subnets, 2 masks +C 10.16.128.0/20 is directly connected, Tunnel20 +L 10.16.132.86/32 is directly connected, Tunnel20 +D 10.16.160.0/20 + [90/25610240] via 10.18.80..226, 7w0d, GigabitEthernet0/0/2.101 + 10.18.80..0/24 is variably subnetted, 11 subnets, 3 masks +D 10.18.80..224/27 is a summary, 7w0d, Null0 +C 10.18.80..224/30 is directly connected, GigabitEthernet0/0/2.101 +L 10.18.80..225/32 is directly connected, GigabitEthernet0/0/2.101 +C 10.18.80..228/30 is directly connected, GigabitEthernet0/0/1.102 +L 10.18.80..229/32 is directly connected, GigabitEthernet0/0/1.102 +D 10.18.80..232/30 + [90/5376] via 10.18.80..226, 7w0d, GigabitEthernet0/0/2.101 +O 10.18.80..240/30 + [110/20] via 10.18.80..230, 7w0d, GigabitEthernet0/0/1.102 +C 10.18.80..240/32 is directly connected, Loopback20 +O 10.18.80..241/32 + [110/11] via 10.18.80..226, 7w0d, GigabitEthernet0/0/2.101 +O 10.18.80..242/32 + [110/20] via 10.18.80..230, 7w0d, GigabitEthernet0/0/1.102 +O 10.18.80..243/32 + [110/30] via 10.18.80..230, 7w0d, GigabitEthernet0/0/1.102 diff --git a/tests/parser_templates/cli/show_ip_route_vrf_all/12.2(33)SXH7.txt b/tests/parser_templates/cli/show_ip_route_vrf_all/12.2(33)SXH7.txt new file mode 100644 index 0000000..b5375b8 --- /dev/null +++ b/tests/parser_templates/cli/show_ip_route_vrf_all/12.2(33)SXH7.txt @@ -0,0 +1,63 @@ +Codes: L - local, C - connected, S - static, R - RIP, M - mobile, B - BGP + D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area + N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2 + E1 - OSPF external type 1, E2 - OSPF external type 2 + i - IS-IS, su - IS-IS summary, L1 - IS-IS level-1, L2 - IS-IS level-2 + ia - IS-IS inter area, * - candidate default, U - per-user static route + o - ODR, P - periodic downloaded static route, H - NHRP, l - LISP + a - application route + + - replicated route, % - next hop override, p - overrides from PfR + +Gateway of last resort is 172.31.0.106 to network 0.0.0.0 + +B* 0.0.0.0/0 [20/0] via 172.31.0.106, 6d17h + 10.0.0.0/8 is variably subnetted, 2 subnets, 2 masks +C 10.242.61.0/24 is directly connected, GigabitEthernet0/0/1.11 +L 10.242.61.1/32 is directly connected, GigabitEthernet0/0/1.11 +B 10.122.254.32/29 [200/0], 6d17h, Null0 +C 10.29.60.62/24 is directly connected, Loopback3 +C 10.29.60.63/24 is directly connected, Loopback4 +B 10.29.192.26/24 [200/0], 6d17h, Null0 +C 10.29.192.26/24 is directly connected, Loopback1 +C 10.29.192.27/24 is directly connected, Loopback2 + 10.31.0.0/16 is variably subnetted, 2 subnets, 2 masks +C 10.31.0.104/29 is directly connected, GigabitEthernet0/0/0 +L 10.31.0.105/32 is directly connected, GigabitEthernet0/0/0 + +Routing Table: ABC +Codes: C - connected, S - static, R - RIP, M - mobile, B - BGP + D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area + N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2 + E1 - OSPF external type 1, E2 - OSPF external type 2 + i - IS-IS, su - IS-IS summary, L1 - IS-IS level-1, L2 - IS-IS level-2 + ia - IS-IS inter area, * - candidate default, U - per-user static route + o - ODR, P - periodic downloaded static route + +Gateway of last resort is 10.20.190.33 to network 0.0.0.0 + + 10.0.0.0/8 is variably subnetted, 13 subnets, 3 masks +D 10.20.190.40/29 + [90/768] via 10.122.254.70, 2w6d, TenGigabitEthernet3/3 +C 10.122.252.0/24 is directly connected, Vlan849 +D 10.122.254.32/29 + [90/768] via 10.122.254.70, 2w6d, TenGigabitEthernet3/3 +C 10.122.254.8/29 is directly connected, TenGigabitEthernet3/1 +S 10.44.126.1/32 [1/0] via 10.44.127.22 +B 10.106.1.0/24 [20/0] via 10.20.190.33, 7w0d + 10.68.51.0/29 is subnetted, 1 subnets +C 10.10.10.0 is directly connected, Vlan848 +B* 0.0.0.0/0 [20/0] via 10.20.190.33, 1d16h + +Routing Table: Test +Codes: L - local, C - connected, S - static, R - RIP, M - mobile, B - BGP + D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area + N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2 + E1 - OSPF external type 1, E2 - OSPF external type 2 + i - IS-IS, su - IS-IS summary, L1 - IS-IS level-1, L2 - IS-IS level-2 + ia - IS-IS inter area, * - candidate default, U - per-user static route + o - ODR, P - periodic downloaded static route, H - NHRP, l - LISP + a - application route + + - replicated route, % - next hop override, p - overrides from PfR + +Gateway of last resort is not set + diff --git a/tests/parser_templates/cli/show_ip_route_vrf_all/main.yaml b/tests/parser_templates/cli/show_ip_route_vrf_all/main.yaml new file mode 100644 index 0000000..96eb22e --- /dev/null +++ b/tests/parser_templates/cli/show_ip_route_vrf_all/main.yaml @@ -0,0 +1,37 @@ +--- +### IOS 12.2(33)SXH78 + +- name: 12.2(33)SXH7 - parse `show ip route vrf *` + command_parser: + file: "{{ playbook_dir }}/../parser_templates/cli/show_ip_route_vrf_all.yaml" + content: "{{ lookup('file', '{{ playbook_dir }}/parser_templates/cli/show_ip_route_vrf_all/12.2(33)SXH7.txt') }}" + register: result + +- name: 12.2(33)SXH7 - test `show ip route vrf *` + assert: + that: + - "'ABC' in vrfs" + - "'routing_table' in vrfs.ABC" + - "'10.20.190.33' in vrfs['ABC']['routing_table']['0.0.0.0/0']['next_hop']" + - "'Test' in vrfs" + - vrfs['Test']['default_route'] == "not set" + +### IOS-XE 03.14.00.S + +- name: 03.14.00.S - parse `show ip route vrf *` + command_parser: + file: "{{ playbook_dir }}/../parser_templates/cli/show_ip_route_vrf_all.yaml" + content: "{{ lookup('file', '{{ playbook_dir }}/parser_templates/cli/show_ip_route_vrf_all/03.14.00.S.txt') }}" + register: result + +- name: 03.14.00.S - test `show ip route vrf *` + assert: + that: + - "'routing_table' in vrfs['Mgmt-intf']" + - vrfs['Def']['routing_table']['0.0.0.0/0']['protocol'] == 'eigrp' + +### Done + +- name: all tests complete + debug: + msg: "All tests for `show ip route vrf *` passed" diff --git a/tests/test_parser_templates.yaml b/tests/test_parser_templates.yaml index 4d78d9c..9eae481 100755 --- a/tests/test_parser_templates.yaml +++ b/tests/test_parser_templates.yaml @@ -29,3 +29,13 @@ include_tasks: parser_templates/cli/show_version/main.yaml vars: system: "{{ cisco_ios['system'] }}" + + - name: Include tests for `show ip route vrf all` + include_tasks: parser_templates/cli/show_ip_route_vrf_all/main.yaml + vars: + vrfs: "{{ cisco_ios['vrf'] }}" + + - name: Include tests for `show ip route` + include_tasks: parser_templates/cli/show_ip_route/main.yaml + vars: + vrfs: "{{ cisco_ios['vrf'] }}" diff --git a/vars/get_facts_command_map.yaml b/vars/get_facts_command_map.yaml index 86094d4..33bd7df 100644 --- a/vars/get_facts_command_map.yaml +++ b/vars/get_facts_command_map.yaml @@ -61,3 +61,17 @@ - all - vrf - routing + +- command: show ip route + parser: show_ip_route.yaml + groups: + - all + - vrf + - routing + +- command: show ip route vrf * + parser: show_ip_route_vrf_all.yaml + groups: + - all + - vrf + - routing