-
Notifications
You must be signed in to change notification settings - Fork 3
/
ise.task_monitor.yaml
186 lines (171 loc) · 7.51 KB
/
ise.task_monitor.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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
---
- name: Monitor ISE Tasks (Patch, Upgrade, Bulk, etc.)
hosts: ise
gather_facts: no
vars:
vars_files:
roles:
#
# Task Monitoring uses REST APIs which requires the ISE Application Server.
# Wait for the ISE Login (Application Server running) if restarted.
#
- ise_login_await
tasks:
- name: Get All Tasks
cisco.ise.tasks_info:
ise_hostname: "{{ ansible_host }}"
ise_username: "{{ ise_username | default( omit ) }}"
ise_password: "{{ ise_password | default( omit ) }}"
register: tasks
- name: Show Task Summary
when:
- tasks is defined
- tasks.ise_response is defined
- tasks.ise_response | count > 0
block:
- name: Show Task Summary
when: tasks.ise_response | count > 1
delegate_to: localhost
vars:
# maxw: 20
head: [
"startTime",
"moduleType",
"executionStatus",
"successCount",
"failCount",
# "detailStatus",
] # 'id','executionStatus'
rows: "{{ tasks.ise_response }}" # | community.general.json_query('[]')
temp: "{{ lookup('template', './templates/list_of_dicts.j2') }}"
ansible.builtin.debug:
msg: "{{ temp }}"
- name: Convert Task Times
loop: "{{ tasks.ise_response | community.general.json_query('[].startTime') }}"
ansible.builtin.debug:
msg:
- '{{ item[0:10] }} | {{ lookup(''ansible.builtin.pipe'', ''date -r {{ item[0:10] }} "+%Y%m%dT%H%M%S-%Z" '') }}'
- name: First Task ID in List
ansible.builtin.debug:
msg: "{{ tasks.ise_response[0].id }}"
- name: Last Task ID in List
ansible.builtin.debug:
msg: "{{ tasks.ise_response[-1].id }}"
- name: Last Task by startTime
ansible.builtin.debug:
msg: "{{ tasks.ise_response | sort(attribute='startTime') | last }}"
# moduleType: [ 'PatchInstall', 'CONFIG BACKUP RESTORE MODULE', ?HotPatchInstall?, ... ]
- name: Last Patch Task
ansible.builtin.debug:
msg: "{{
tasks.ise_response
| selectattr('moduleType', 'equalto', 'PatchInstall')
| sort(attribute='startTime')
| last
| default([])
}}"
- name: Last Backup/Restore Task
ansible.builtin.debug:
msg: "{{
tasks.ise_response
| selectattr('moduleType', 'equalto', 'CONFIG BACKUP RESTORE MODULE')
| sort(attribute='startTime')
| last
| default([])
}}"
- name: Set Last Task ID
ansible.builtin.set_fact:
task_id: "{{ (tasks.ise_response | sort(attribute='startTime') | last).id }}"
- name: Monitor Last Task
when:
- tasks is defined
- tasks.ise_response is defined
- tasks.ise_response | count > 0
block:
- name: Monitor Last Task {{ task_id }}
cisco.ise.tasks_info:
ise_hostname: "{{ ansible_host }}"
ise_username: "{{ ise_username | default( omit ) }}"
ise_password: "{{ ise_password | default( omit ) }}"
taskId: "{{ task_id }}"
until: task_status.ise_response.failCount != None or task_status.ise_response.successCount != None
retries: 1000
# delay: 10 # Default: 0. Seconds to wait before first check
# sleep: 10 # Default: 1. Seconds to sleep between checks
# timeout: 1800 # Default: 300. Stop checking after <seconds>
register: task_status
# task_status.ise_response:
# detailStatus:
# - restore 20221022_dCloud_3.2_Demos_iseadmin-CFG10-221022-1725.tar.gpg from repository ftp.trust0.net":" success
# executionStatus: COMPLETED_WITH_SUCCESS
# failCount: null
# id: 5c1264c0-523f-11ed-ba05-226398db73b8
# moduleType: CONFIG BACKUP RESTORE MODULE
# resourcesCount: 1
# startTime: '1666466759948'
# successCount: 1
- name: Show task_status
ansible.builtin.debug:
msg:
- "Fail Count: {{ (task_status.ise_response.failCount == None) | ternary(0, task_status.ise_response.failCount) }}"
- "Success Count: {{ (task_status.ise_response.successCount == None) | ternary(0, task_status.ise_response.successCount) }}"
- "Execution Status: {{ task_status.ise_response.executionStatus }}"
- "Detail Status: {{ task_status.ise_response.detailStatus }}"
- "Start Time: {{ task_status.ise_response.startTime }}" # milliseconds
- "Time Elapsed: {{ ( '%s' | strftime | int ) - ( (task_status.ise_response.startTime | string | length > 12)
| ternary(task_status.ise_response.startTime[0:-3], task_status.ise_response.startTime) | int ) }}"
#------------------------------------------------------------------------
# Restore Examples
#------------------------------------------------------------------------
# ```
# tasks:
# changed: false
# failed: false
# ise_response:
# - detailStatus:
# - restore 20221013_Demo-CFG10-221013-1427.tar.gpg from repository ftp.trust0.net":" success
# executionStatus: COMPLETED_WITH_SUCCESS
# failCount: null
# id: af29e530-5216-11ed-96b2-6aa36a887e9d
# moduleType: CONFIG BACKUP RESTORE MODULE
# resourcesCount: 1
# startTime: '1666449289987'
# successCount: 1
# ```
#------------------------------------------------------------------------
# Backup Examples
#------------------------------------------------------------------------
# ```
# - detailStatus:
# - 'backup 20221022-095326-CFG10-221022-1653.tar.gpg to repository ftp.trust0.net: success'
# executionStatus: COMPLETED_WITH_SUCCESS
# failCount: null
# id: 17106d50-522a-11ed-ba05-226398db73b8
# moduleType: CONFIG BACKUP RESTORE MODULE
# resourcesCount: 1
# startTime: '1666457624741'
# successCount: 1
# - detailStatus:
# - Backup is in progress...
# executionStatus: IN_PROGRESS
# failCount: null
# id: 93d0eeb0-522e-11ed-ba05-226398db73b8
# moduleType: CONFIG BACKUP RESTORE MODULE
# resourcesCount: 1
# startTime: '1666459552027'
# successCount: null
# ```
#------------------------------------------------------------------------
# Patch Examples
#------------------------------------------------------------------------
# ```
# - detailStatus:
# - '{"patchNumber":"3","repositoryName":"repository.trust0.net","patchName":"ise-patchbundle-3.1.0.518-Patch3-22042809.SPA.x86_64.tar.gz","status":"Patch Installed Successfully"}'
# executionStatus: COMPLETED_WITH_SUCCESS
# failCount: null
# id: 4aa6d570-0098-11ed-86ea-dad0d8ee139d
# moduleType: PatchInstall
# resourcesCount: 1
# startTime: '1657488960583'
# successCount: 1
# ```