-
Notifications
You must be signed in to change notification settings - Fork 0
/
Verify_bgp.yaml
39 lines (32 loc) · 1.05 KB
/
Verify_bgp.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
---
- name: Check BGP Status
hosts: nxos-01
gather_facts: no
vars:
ansible_network_os: nxos
ansible_connection: network_cli
tasks:
- name: Run show ip bgp summary
cisco.nxos.nxos_command:
commands: show ip bgp summary
register: bgp_output
- name: Debug raw output
debug:
var: bgp_output.stdout_lines
- name: Parse BGP neighbors state
set_fact:
bgp_neighbors: "{{ bgp_output.stdout[0] | regex_findall('\\d+\\.\\d+\\.\\d+\\.\\d+\\s+\\d+\\s+\\d+\\s+\\d+\\s+\\d+\\s+\\d+\\s+\\d+\\s+\\d+\\s+(\\d+|\\d+:\\d+:\\d+)') }}"
- name: Determine BGP status
set_fact:
bgp_up: "{{ bgp_neighbors | select('match', '^\\d+$') | list | length > 0 }}"
- name: Display BGP status
debug:
msg: "BGP is {{ 'up' if bgp_up else 'down' }}"
- name: Assert BGP is up
assert:
that: bgp_up
fail_msg: "BGP is not up"
success_msg: "BGP is up and running"
- name: Show BGP neighbor states
debug:
msg: "BGP neighbor states: {{ bgp_neighbors }}"