Debian Codegraph @

ansible_collections/dellemc/openmanage/roles/idrac_reset/tasks/main.yml

raw symbols SCIP
1 ---
2 - name: Check whether atleast one of 'IDRAC_USERNAME' or username is provided
3 ansible.builtin.fail:
4 msg: "Ensure the value for environment variable 'IDRAC_USERNAME' or
5 the argument 'username' is set."
6 when: username is not defined and not lookup('env', 'IDRAC_USERNAME')
7
8 - name: Check whether atleast one of 'IDRAC_PASSWORD' or password is provided
9 ansible.builtin.fail:
10 msg: "Ensure the value for environment variable 'IDRAC_PASSWORD' or
11 the argument 'password' is set."
12 when: password is not defined and not lookup('env', 'IDRAC_PASSWORD')
13
14 - name: Setting uri options
15 ansible.builtin.set_fact:
16 idrac_opts: &idrac_opts
17 user: "{{ username | default(lookup('env', 'IDRAC_USERNAME')) }}"
18 password: "{{ password | default(lookup('env', 'IDRAC_PASSWORD')) }}"
19 validate_certs: "{{ validate_certs }}"
20 ca_path: "{{ ca_path | default(omit) }}"
21 headers: "{{ idrac_reset_uri_headers }}"
22 body_format: "{{ idrac_reset_uri_body_format }}"
23 return_content: "{{ idrac_reset_uri_return_content }}"
24 force_basic_auth: "{{ idrac_reset_force_basic_auth }}"
25 timeout: "{{ https_timeout }}"
26 no_log: true
27
28 - name: Get connection
29 ansible.builtin.uri:
30 <<: *idrac_opts
31 url: "https://{{ hostname }}:{{ https_port }}/redfish/v1/Systems"
32 method: "GET"
33 status_code: "{{ idrac_reset_uri_status_code }}"
34 register: idrac_reset_connection
35 delegate_to: "{{ idrac_reset_task_delegate }}"
36
37 - name: Validate hostname or certificate.
38 ansible.builtin.fail:
39 msg: "{{ idrac_reset_connection.msg }}"
40 when: idrac_reset_connection.status == -1
41
42 - name: Validate credentials.
43 ansible.builtin.fail:
44 msg: "{{ idrac_reset_invalid_creds }}"
45 when: idrac_reset_connection.status == 401
46
47 - name: Get the manager firmware version
48 ansible.builtin.uri:
49 url: "https://{{ hostname }}:{{ https_port }}/\
50 redfish/v1/Managers/iDRAC.Embedded.1\
51 ?$select=FirmwareVersion"
52 <<: *idrac_opts
53 method: GET
54 register: idrac_reset_firmware_version
55 delegate_to: "{{ idrac_reset_task_delegate }}"
56
57 - name: Set manager firmware version
58 ansible.builtin.set_fact:
59 idrac_reset_fwm_ver: "{{ idrac_reset_firmware_version.json.FirmwareVersion }}"
60
61 - name: Check LC status
62 ansible.builtin.include_tasks: lcstatus_check.yml
63
64 - name: Perform graceful restart operation
65 ansible.builtin.uri:
66 url: "https://{{ hostname }}:{{ https_port }}{{ idrac_reset_graceful_restart_api }}"
67 <<: *idrac_opts
68 method: "POST"
69 body: '{"ResetType": "GracefulRestart"}'
70 status_code: 204
71 register: idrac_reset_restart_result
72 delegate_to: "{{ idrac_reset_task_delegate }}"
73 when: reset_to_default is not defined
74
75 - name: Perform reset operation
76 ansible.builtin.uri:
77 url: "https://{{ hostname }}:{{ https_port }}{{ idrac_reset_reset_api }}"
78 <<: *idrac_opts
79 method: "POST"
80 body: '{"ResetType": "{{ reset_to_default }}" }'
81 status_code: [200, 405]
82 register: idrac_reset_result
83 delegate_to: "{{ idrac_reset_task_delegate }}"
84 when: reset_to_default is defined
85 ignore_errors: true
86
87 - name: Message out the iDRAC 8 support for reset operation
88 ansible.builtin.debug:
89 msg: "iDRAC reset operations are not supported"
90 when:
91 - idrac_reset_result is not skipped and idrac_reset_result is defined
92 - idrac_reset_result.status is defined
93 - idrac_reset_result.status == 405
94
95 - name: Check for iDRAC connection
96 when: (idrac_reset_result is not skipped and idrac_reset_result.status == 200)
97 or (idrac_reset_restart_result is not skipped and idrac_reset_restart_result.status == 204)
98 block:
99 - name: Wait for port 443 to become open on the host
100 ansible.builtin.wait_for:
101 host: "{{ hostname }}"
102 port: "{{ https_port }}"
103 delay: "{{ idrac_reset_delay_for_idrac_connection }}"
104 timeout: "{{ idrac_reset_wait_for_idrac_reachable }}"
105 connect_timeout: "{{ idrac_reset_connect_timeout }}"
106 sleep: "{{ idrac_reset_sleep_interval }}"
107 active_connection_states:
108 - "ESTABLISHED"
109 when:
110 - wait_for_idrac is true
111 delegate_to: "{{ idrac_reset_task_delegate }}"
112 register: idrac_reset_connection_status
113 ignore_errors: true
114
115 - name: Check LC status after restart/reset operation
116 ansible.builtin.include_tasks: lcstatus_check.yml
117 when:
118 - wait_for_idrac is true
119
120 - name: Set fact when restart is triggered successfully
121 ansible.builtin.set_fact:
122 idrac_reset_out: {msg: "{{ idrac_reset_restart_trigger }}"}
123 when:
124 - wait_for_idrac is false
125 - idrac_reset_restart_result is not skipped and idrac_reset_restart_result.status == 204
126
127 - name: Set fact when reset is triggered successfully
128 ansible.builtin.set_fact:
129 idrac_reset_out: {msg: "{{ idrac_reset_reset_trigger }}"}
130 when:
131 - wait_for_idrac is false
132 - idrac_reset_result is not skipped and idrac_reset_result.status == 200
133
134 - name: Set fact when restart is done successfully
135 ansible.builtin.set_fact:
136 idrac_reset_out: {msg: "{{ idrac_reset_idrac_restarted_success }}"}
137 when:
138 - wait_for_idrac is true
139 - idrac_reset_connection_status is not failed
140 - idrac_reset_restart_result is not skipped and idrac_reset_restart_result.status == 204
141
142 - name: Set fact when reset is done successfully
143 ansible.builtin.set_fact:
144 idrac_reset_out: {msg: "{{ idrac_reset_success }}"}
145 when:
146 - wait_for_idrac is true
147 - idrac_reset_connection_status is not failed
148 - idrac_reset_result is not skipped and idrac_reset_result.status == 200