-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpb.validate.lldp.yaml
72 lines (72 loc) · 2.6 KB
/
pb.validate.lldp.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
---
- name: Validate
hosts: fabric
connection: local
gather_facts: no
tasks:
- name: "prepate tmp"
file: path=./tmp state=directory
- name: include cabling vars
include_vars: ./cabling_vars/{{ inventory_hostname }}.yaml
- name: "Generate validation rules"
template:
src: "./templates/validate/lldp.j2"
dest: "./tmp/{{ inventory_hostname }}.yaml"
changed_when: no
check_mode: no
- name: "Read validation rules, gather data and verify it against rules"
ignore_errors: yes
napalm_validate:
hostname: "{{ ansible_ssh_host }}"
username: "root"
dev_os: "{{ os }}"
password: "Juniper"
optional_args:
port: "{{ ansible_ssh_port }}"
validation_file: "./tmp/{{ inventory_hostname }}.yaml"
register: validation
- name: "Failed report"
debug:
msg: "{{ validation.compliance_report|to_nice_json }}"
when: not validation.compliance_report.complies
tags: [print_action]
- name: "Failed Compliance Report prepare"
file: path=./reports/tmp state=directory
- name: "Failed Compliance Report prepare"
file: path=./reports/lldp.report state=absent
- name: "Failed Compliance Report save"
copy:
dest: ./reports/tmp/{{ inventory_hostname }}.report
content: |
=====
{{ inventory_hostname }} PORTS
{% for name,state in validation.compliance_report.get_lldp_neighbors.present.items() %}
{% if not state.complies %}
----
NEIGHBOR {{ state.actual_value[0].hostname }} PORT {{ state.actual_value[0].port }}
TO DEVICE_CHECK {{ 'OK' if state.actual_value[0].hostname == state.expected_value[0].hostname else 'FAIL' }}
TO PORT_CHECK {{ 'OK' if state.actual_value[0].port == state.expected_value[0].port else 'FAIL' }}
SHOULD BE NEIGHBOR {{ state.expected_value[0].hostname }} PORT {{ state.expected_value[0].port }}
----
{% endif %}
{% endfor %}
=====
delegate_to: localhost
when: not validation.compliance_report.complies
- name: "Failed Compliance Report save"
assemble:
src: ./reports/tmp/
dest: ./reports/lldp.report
- name: "delete files"
file: path=./reports/tmp/{{ inventory_hostname }}.report state=absent
- name: 'delete files'
file: path=./tmp/{{ inventory_hostname }}.yaml state=absent
- name: "Failed Compliance Report"
fail:
msg: "{{ validation.compliance_report|to_nice_json }}"
when: not validation.compliance_report.complies
- name: "Compliance report"
debug:
msg: "Complies"
when: validation.compliance_report.complies
tags: [print_action]