-
Notifications
You must be signed in to change notification settings - Fork 0
/
HealthCheck.yml
162 lines (135 loc) · 5.37 KB
/
HealthCheck.yml
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
---
- name: L3LS Health Check
hosts: all
gather_facts: no
connection: local
vars:
item: "foo"
vars_files:
- ./pinghosts.yml
tasks:
- name: Set Date Stamp
set_fact: date="{{lookup('pipe','date +%Y%m%d')}}"
tags: date_stamp
run_once: true
- name: Set Time Stamp
set_fact: time="{{lookup('pipe','date +%Y%m%d%H%M%S')}}"
tags: time_stamp
run_once: true
- name: Part 1 - Validate OSPF Health
block:
- name: Task 1 - Capture current list of OSPF Neighbors
eos_command:
commands:
- show ip ospf neighbor | json
register: ospfneighbors
- name: Task 2 - Setting Fact - OSPF Neighbor Count
set_fact:
ospfneigh_count: "{{ ospfneighbors.stdout[0].vrfs.default.instList['100'].ospfNeighborEntries | length }}"
- name: Task 3 - Validate that all expectected OSPF Neighbors are in place
assert:
that:
- "{{ ospfneigh_count | int >= ospfadjcount }}"
fail_msg: "{{ inventory_hostname }} only has {{ ospfneigh_count }} neighbors. It should have {{ ospfadjcount }}!"
- name: Task 4 - Capture list of interfaces that have OSPF enabled
tags: ospfint
eos_command:
commands:
- show ip ospf interface brief | json
register: ospfints
- name: Task 5 - Set fact - List of expected OSPF Interfaces
tags: ospfint
set_fact:
ospfints_expected: "{{ lookup('template', './ospfintlist.j2') }}"
- name: Task 6 - Set Fact - List of actual OSPF interfaces
tags: ospfint
set_fact:
ospfints_actual: "{{ ospfints.stdout[0].vrfs.default.instList['100'].interfaces | list }}"
- name: Task 7 - Validate that all expected interfaces are running OSPF
tags: ospfint
assert:
that:
- "'{{ item }}' in ospfints.stdout[0].vrfs.default.instList['100'].interfaces"
fail_msg: "{{ inventory_hostname }} Does not have the list of active OSPF interfaces that we expected."
with_items:
- "{{ ospfints_expected }}"
- name: Task 8 - Check for any interfaces running OSPF that should not be
tags: ospfint
assert:
that:
- "'{{ item }}' in ospfints_expected"
fail_msg: "{{ inventory_hostname }} has interfaces running OSPF that we did not expect."
with_items:
- "{{ ospfints_actual }}"
- name: Task 9 - Capture OSPF database summary for the area from any node
tags: ospfdb
eos_command:
commands:
- show ip ospf database database-summary | json
register: ospfdbsum_truth
run_once: true
- name: Task 10 - Capture the OSPF database summary from every node within the area
tags: ospfdb
eos_command:
commands:
- show ip ospf database database-summary | json
register: ospfdbsum_node
- name: Task 11 - Validate that the OSPF database summary is consistent within the area
tags: ospfdb
assert:
that: " ospfdbsum_truth.stdout[0].vrfs.default.instList['100'] == ospfdbsum_node.
stdout[0].vrfs.default.instList['100'] "
fail_msg: "The LSDB (OSPF Database) is not consistent on all nodes in Area 0"
rescue:
- name: Send a Slack Message reporting the failure
slack:
token: T9E1Z68H3/BC10PAM42/9jtmxAXW4LeGLuD7pABgMvr5
msg: "*{{ inventory_hostname }} failed the OSPF Health Check.*\n\n *It failed on task:* {{ ansible_failed_task.name }}\n\n*The error message was:* {{ ansible_failed_task.args.fail_msg }}."
color: danger
delegate_to: localhost
- name: Part 2 - Validate Connectivity via Pings
tags: ping
block:
- name: Ping the hosts
tags: ping
eos_command:
commands:
- "ping {{ item }}"
with_items: "{{ pinghosts }}"
register: pingresult
- name: testing
tags: ping
debug:
var: pingresult
- name: Get length of Ping Result output
tags: ping
set_fact:
totalpings: "{{ pingresult.results | length }}"
- name: Set Fact - Ping Result output length converted to integer
tags: ping
set_fact:
totalpingsint: "{{ totalpings | int - 1 }}"
- name: Create list of ping iterations
tags: ping
set_fact:
foo: "{{ foo | default([]) + [item | int] }}"
with_sequence: "start=0 end={{totalpingsint}} stride=1"
- name: Validate Ping Results
tags: ping
assert:
that:
- "'{{item.0}}' in pingresult.results[{{item.1}}].stdout[0]"
- "'0% packet loss' in pingresult.results[{{item.1}}].stdout[0]"
fail_msg: "{{ inventory_hostname }} was not able to successfully ping all hosts"
with_together:
- "{{ pinghosts }}"
- "{{ foo }}"
rescue:
- name: Send a Slack Message reporting the failure
tags: ping
slack:
token: T9E1Z68H3/BC10PAM42/9jtmxAXW4LeGLuD7pABgMvr5
msg: "*{{ inventory_hostname }} failed the Health Check.*\n\n *It failed on task:* {{ ansible_failed_task.name }}\n\n*The
error message was:* {{ ansible_failed_task.args.fail_msg }}."
color: danger
delegate_to: localhost