-
Notifications
You must be signed in to change notification settings - Fork 4
/
03_audit_nautobot.yml
63 lines (57 loc) · 2.18 KB
/
03_audit_nautobot.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
---
# Playbook to read information from device and Nautobot and compare
- name: "PLAY 1: READ NETWORK DEVICE INFORMATION AND COMPARE NAUTOBOT"
hosts: platforms_ios, platforms_eos, platforms_nxos
become: yes
become_method: enable
connection: ansible.netcommon.network_cli
vars:
url: "{{ lookup('env', 'NAUTOBOT_URL') }}"
token: "{{ lookup('env', 'NAUTOBOT_TOKEN') }}"
nautobot_headers:
Content-Type: "application/json"
Authorization: "token {{ token }}"
nautobot_serial_list: []
device_serial_list: []
ssl_verify: True
tasks:
- name: "TASK 1A: NXOS >> GET NXOS FACTS"
nxos_facts:
gather_subset: "!config"
when: "ansible_network_os == 'nxos'"
- name: "TASK 1B: IOS >> GET IOS FACTS"
ios_facts:
gather_subset: "!config"
when: "ansible_network_os == 'ios'"
- name: "TASK 1C: EOS >> GATHER FACTS FROM DEVICE"
eos_facts:
gather_subset: "!config"
when: "ansible_network_os == 'eos'"
- name: "TASK 2: NAUTOBOT >> GATHER NAUTOBOT DATA"
uri:
url: "{{ url }}/api/dcim/devices/?q={{ inventory_hostname }}"
headers: "{{ nautobot_headers }}"
method: GET
status_code: 200
validate_certs: "{{ ssl_verify }}"
register: nautobot_device_results
- name: "TASK 3: SYS >> BUILD NAUTOBOT SERIAL NUMBER LIST FROM NAUTOBOT RESPONSES"
set_fact:
nautobot_serial_list: "{{ nautobot_serial_list + [ item.serial ] }}"
loop: "{{ nautobot_device_results['json']['results'] }}"
loop_control:
label: "{{ item.name }}"
- name: "TASK 4: SYS >> BUILD IOS DEVICE SERIAL LIST USING FILTER"
set_fact:
device_serial_list: "{{ ansible_facts | get_ciscoios_serial_list }}"
- name: "TASK 5: SYS >> VERIFY DEVICE DATA VS NAUTOBOT - CUSTOM FILTER"
assert:
that:
- "device_serial_list | compare_lists(nautobot_serial_list)"
fail_msg:
- "Device Serial List: {{ device_serial_list }}"
- "Nautobot Serial List: {{ nautobot_serial_list }}"
success_msg:
- "Device Serial List: {{ device_serial_list }}"
- "Nautobot Serial List: {{ nautobot_serial_list }}"
...