-
Notifications
You must be signed in to change notification settings - Fork 0
/
redfish_bios_attributes.yml
194 lines (176 loc) · 6.46 KB
/
redfish_bios_attributes.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
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
187
188
189
190
191
192
193
194
---
- hosts: idrac
name: Set bios attributes
connection: local
gather_facts: no
vars:
ansible_python_interpreter: python
bios_vars_file_name: "redfish_bios_vars.yml"
tasks:
- name: Load BIOS attributes from the variable file
include_vars:
file: "{{ bios_vars_file_name }}"
name: bios_attributes
tags:
- set-bios-attributes
- name: Get the BIOS attributes
uri:
url: "https://{{inventory_hostname}}/redfish/v1/Systems/System.Embedded.1/Bios"
user: "{{ idrac_user }}"
password: "{{ idrac_password }}"
method: GET
headers:
accept: "application/json"
force_basic_auth: no
validate_certs: no
register: result
tags:
- get-bios-attributes
- set-bios-attributes
- name: Add current bios attributes to a fact variable
set_fact:
current_bios_attributes: "{{ result.json.Attributes }}"
tags:
- set-bios-attributes
- name: Iterate and add only those bios attributes to dict that have a different value
set_fact:
new_bios_attributes: "{{ new_bios_attributes | default({}) | combine( { item.key: item.value } ) }}"
when: item.key in current_bios_attributes and item.value != current_bios_attributes[item.key]
loop: "{{ bios_attributes | dict2items }}"
tags:
- set-bios-attributes
- name: Iterate and add only those bios attributes to dict that are already set
set_fact:
already_set_bios_attributes: "{{ already_set_bios_attributes | default({}) | combine( { item.key: item.value } ) }}"
when: item.key in current_bios_attributes and item.value == current_bios_attributes[item.key]
loop: "{{ bios_attributes | dict2items }}"
tags:
- set-bios-attributes
- name: Iterate and add only those bios attributes to dict that are not found
set_fact:
not_found_bios_attributes: "{{ not_found_bios_attributes | default ({}) | combine( { item.key: item.value } ) }}"
when: item.key not in current_bios_attributes
loop: "{{ bios_attributes | dict2items }}"
tags:
- set-bios-attributes
- debug:
msg: "Following attributes will be applied: {{ new_bios_attributes }}"
when: new_bios_attributes is defined
tags:
- get-bios-attributes
- set-bios-attributes
- debug:
msg: "Following attributes are already set: {{ already_set_bios_attributes }}"
when: already_set_bios_attributes is defined
tags:
- get-bios-attributes
- set-bios-attributes
- debug:
msg: "Following attributes were not found: {{ not_found_bios_attributes }}"
when: not_found_bios_attributes is defined
tags:
- get-bios-attributes
- set-bios-attributes
- name: Submit a PATCH operation to set BIOS attributes
uri:
url: "https://{{inventory_hostname}}/redfish/v1/Systems/System.Embedded.1/Bios/Settings"
user: "{{ idrac_user }}"
password: "{{ idrac_password }}"
method: PATCH
headers:
accept: "application/json"
content-type: "application/json"
body:
"@Redfish.SettingsApplyTime": {"ApplyTime": "OnReset"}
"Attributes": "{{ new_bios_attributes }}"
body_format: "json"
force_basic_auth: no
validate_certs: no
status_code: [200, 202]
when: new_bios_attributes is defined and new_bios_attributes.keys()|length > 0
register: bios_config_response
tags:
- set-bios-attributes
- name: Check if location is present in the response header and store it in a fact variable so that we use it for monitoring the BIOS config job status
set_fact:
bios_config_job_url: "{{ result.location }}"
when: new_bios_attributes is defined and bios_config_response.location is defined
tags:
- set-bios-attributes
- name: If no location is present in the response header message, then we need to create a BIOS config job
uri:
url: "https://{{inventory_hostname}}/redfish/v1/Managers/iDRAC.Embedded.1/Jobs"
user: "{{ idrac_user }}"
password: "{{ idrac_password }}"
method: POST
headers:
accept: "application/json"
content-type: "application/json"
body:
"TargetSettingsURI": "/redfish/v1/Systems/System.Embedded.1/Bios/Settings"
body_format: "json"
force_basic_auth: no
validate_certs: no
status_code: [200, 202]
register: bios_config_job_response
when: new_bios_attributes is defined and bios_config_response.location is not defined
tags:
- set-bios-attributes
- name: Check if location is present in the response header and store it in a fact variable so that we use it for monitoring the BIOS config job status
set_fact:
bios_config_job_url: "{{ bios_config_job_response.location }}"
when: new_bios_attributes is defined and bios_config_job_response.location is defined
tags:
- set-bios-attributes
- name: Fail if the JOB URL is not received
fail:
msg: "Failed to rceive BIOS configuration JOB URL in the HTTPS response. Cannot proceed with BIOS configuration task."
when: new_bios_attributes is defined and bios_config_job_url is not defined
tags:
- set-bios-attributes
- name: Get the JOB details
uri:
url: "{{ bios_config_job_url }}"
user: "{{ idrac_user }}"
password: "{{ idrac_password }}"
method: GET
headers:
accept: "application/json"
force_basic_auth: no
validate_certs: no
status_code: [200, 202]
register: bios_config_task
when: new_bios_attributes is defined
tags:
- set-bios-attributes
- name: Reboot server to apply the BIOS settings
redfish_command:
category: Systems
command: PowerReboot
baseuri: "{{ inventory_hostname }}"
username: "{{ idrac_user }}"
password: "{{ idrac_password }}"
register: result
when: new_bios_attributes is defined
tags:
- set-bios-attributes
- name: loop over the JOB until it completes or fails
uri:
url: "{{ bios_config_job_url }}"
user: "{{ idrac_user }}"
password: "{{ idrac_password }}"
method: GET
headers:
accept: "application/json"
force_basic_auth: no
validate_certs: no
status_code: [200, 202]
register: result
when: new_bios_attributes is defined
until: result.json['JobState'] == 'Completed' or result.json['JobState'] == 'Failed'
retries: 15
delay: 60
changed_when: result.json['JobState'] == 'Completed'
failed_when: result.json['JobState'] == 'Failed'
tags:
- set-bios-attributes