forked from networkRob/ansible-cvp-modules
-
Notifications
You must be signed in to change notification settings - Fork 0
/
get-cvp-eos-xcvrs.yaml
140 lines (126 loc) · 4.28 KB
/
get-cvp-eos-xcvrs.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
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
---
- hosts: localhost
gather_facts: yes
connection: local
vars:
xcvr_eval: "40GBASE-UNIV"
xcvr_csv: "results/xcvrCheck-{{ ansible_date_time.date }}-{{ ansible_date_time.time }}.csv"
cvp_auth_url: "https://{{ cvp_server }}/cvpservice/login/authenticate.do"
cvp_inventory_pre: "https://{{ cvp_server }}/cvpservice/inventory/getInventory.do?startIndex=0&endIndex=0"
cvp_inventory: "https://{{ cvp_server }}/cvpservice/inventory/devices"
switch_sn: []
switch_hostname: {}
tasks:
- name: Setup REST API Session
uri:
url: "{{ cvp_auth_url }}"
method: POST
validate_certs: no
headers:
Accept: "application/json"
Content-Type: "application/json"
body_format: "json"
body:
userId: "{{ cvp_user }}"
password: "{{ cvp_pass }}"
force_basic_auth: yes
status_code: 200,201
register: login
- name: Get CVP Version
uri:
url: "https://{{ cvp_server }}/cvpservice/cvpInfo/getCvpInfo.do"
method: GET
validate_certs: no
return_content: yes
headers:
Cookie: "{{ login.set_cookie }}"
register: cvp_version
- name: Parse CVP Version
set_fact:
cvp_version_major: "{{ cvp_version.json.version.split('.')[:2] | join('.') }}"
- name: Check CVP Version
set_fact:
cvp_inventory: "{{ cvp_inventory_pre }}"
when:
- cvp_version_major == '2018.1'
- name: Get list of devices
uri:
url: "{{ cvp_inventory_pre if cvp_version_major == '2018.1' else cvp_inventory }}"
method: GET
validate_certs: no
return_content: yes
headers:
Cookie: "{{ login.set_cookie }}"
register: switch_list
- name: Get Serial Numbers
set_fact:
switch_sn: '{{ switch_sn + [item.serialNumber] }}'
switch_hostname: "{{ switch_hostname | combine({item.serialNumber:item.fqdn}) }}"
loop: "{{ switch_list.json.netElementList if cvp_version_major == '2018.1' else switch_list.json }}"
when: item.serialNumber != ""
- name: Get list of ports
uri:
url: "https://{{ cvp_server }}/api/v1/rest/{{ item }}/Sysdb/interface/eth/portid/portId"
method: GET
validate_certs: no
return_content: yes
headers:
Cookie: "{{ login.set_cookie }}"
loop: "{{ switch_sn }}"
register: port_list
- name: Gather All Interfaces
rcvp_telem:
cvp_arg: Intfs
sw_ports: "{{ port_list.results }}"
register: all_intfs
- name: Get status on each port_list
uri:
url: https://{{ cvp_server }}/api/v1/rest/{{ item.0.serialNumber }}/Sysdb/hardware/archer/xcvr/status/all/{{ item.1 }}
method: GET
validate_certs: no
return_content: yes
body_format: "json"
headers:
Cookie: "{{ login.set_cookie }}"
with_subelements:
- "{{ all_intfs.results }}"
- ports
register: port_status
- name: Logout of CVP
uri:
url: "https://{{ cvp_server }}/cvpservice/login/logout.do"
method: POST
validate_certs: no
return_content: yes
headers:
Cookie: "{{ login.set_cookie }}"
- name: Evaluate Switch Port Xcvrs
rcvp_telem:
cvp_arg: Eval
sw_ports: "{{ port_status.results }}"
register: port_xcvr
- name: Create New Result csv file
lineinfile:
path: "{{ xcvr_csv }}"
line: "fqdn,serialNumber,interface,xcvr"
insertafter: EOF
create: yes
- name: Check for {{ xcvr_eval }}
lineinfile:
path: "{{ xcvr_csv }}"
line: "{{ switch_hostname[item.serialNumber] }},{{ item.serialNumber }},{{ item.interface }},{{ item.xcvr }}"
insertafter: EOF
loop: "{{ port_xcvr.results }}"
when: item.xcvr == xcvr_eval
- name: Sending an e-mail using Gmail SMTP servers
mail:
host: "{{ smtp_server }}"
port: "{{ smtp_port }}"
username: "{{ email_username }}"
password: "{{ email_password }}"
to: "{{ email_users }}"
subject: Ansible-XCVR-report
body: System {{ ansible_hostname }} XCVR Report information attached.
attach:
- "{{ xcvr_csv }}"
delegate_to: localhost