forked from Isilon/ansible_guide_examples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplaybook-isilonURInetworkAudit.yml
96 lines (84 loc) · 3.45 KB
/
playbook-isilonURInetworkAudit.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
---
- name: Isilon check network interfaces
hosts: isilon82DC1
gather_facts: yes
vars:
DateTimeStamp: "{{ansible_date_time.date}}.{{ansible_date_time.time}}"
IsilonURL: https://{{ ansible_host }}:8080
IsilonPreviousInterfaces: ~/playarea/Isilon/IsilonAPI/auditlogs/IsilonPreviousInterfaces.info
IsilonCurrentInterfaces: ~/playarea/Isilon/IsilonAPI/auditlogs/IsilonCurrentInterfaces.info
IsilonNetworkOriginal: ~/playarea/Isilon/IsilonAPI/auditlogs/IsilonNetwork.Original
IsilonNetworkChanged: ~/playarea/Isilon/IsilonAPI/auditlogs/IsilonNetwork.Changed
tasks:
- name: Get isilon API session IDs
uri:
url: "{{ IsilonURL }}/session/1/session"
method: POST
validate_certs: no
### body: "{{ lookup('file','/root/auth.json') }}"
body_format: json
body:
{
username: ansible,
password: password01,
services: ["platform", "namespace"]
}
status_code: 201
register: results_login
- name: touch previous interface output to ansible server
local_action: file state=touch path={{ IsilonPreviousInterfaces }}
changed_when: false
- name: get current isilon API network interfaces
uri:
url: "{{ IsilonURL }}/platform/7/network/interfaces"
method: GET
return_content: no
validate_certs: no
body_format: json
headers:
Cookie: "isisessid={{ results_login.cookies.isisessid }}"
X-CSRF-Token: "{{ results_login.cookies.isicsrf }}"
referer: "{{ IsilonURL }}"
changed_when: false
register: results_interfaces
- name: Save current interface output to ansible server
local_action: copy content={{ results_interfaces.json }} dest={{ IsilonCurrentInterfaces }}
changed_when: false
- name: Compare current and previous isilon API network interfaces
uri:
url: "{{ IsilonURL }}/platform/7/network/interfaces"
method: GET
return_content: no
validate_certs: no
body_format: json
headers:
Cookie: "isisessid={{ results_login.cookies.isisessid }}"
X-CSRF-Token: "{{ results_login.cookies.isicsrf }}"
referer: "{{ IsilonURL }}"
register: compare_interfaces
changed_when: lookup('file', IsilonPreviousInterfaces ) != lookup('file', IsilonCurrentInterfaces )
notify: save_changed
- name: Execute handlers
meta: flush_handlers
- name: save interface output to ansible server for next run
local_action: copy content={{ compare_interfaces.json }} dest={{ IsilonPreviousInterfaces }}
changed_when: false
- name: Delete isilon API session IDs
uri:
url: "{{ IsilonURL }}/session/1/session"
method: DELETE
validate_certs: no
body_format: json
headers:
Cookie: "isisessid={{ results_login.cookies.isisessid }}"
X-CSRF-Token: "{{ results_login.cookies.isicsrf }}"
referer: "{{ IsilonURL }}"
status_code: 204
register: results_DEL_cookie
### Save previous and current changes for audit purposes ###
handlers:
- name: save_changed
local_action: copy src={{ IsilonPreviousInterfaces }} dest={{ IsilonNetworkOriginal }}.{{ DateTimeStamp }}.log
notify: save_original
- name: save_original
local_action: copy content={{ compare_interfaces.json }} dest={{ IsilonNetworkChanged }}.{{ DateTimeStamp }}.log