| 1 |
--- |
| 2 |
- name: Converge idrac_gather_facts for Power Supply |
| 3 |
hosts: all |
| 4 |
gather_facts: false |
| 5 |
vars: |
| 6 |
hostname: "{{ lookup('env', 'IDRAC_IP') }}" |
| 7 |
username: "{{ lookup('env', 'IDRAC_USER') }}" |
| 8 |
password: "{{ lookup('env', 'IDRAC_PASSWORD') }}" |
| 9 |
idrac_port: "{{ lookup('env', 'IDRAC_PORT') }}" |
| 10 |
validate_certs: false |
| 11 |
target: |
| 12 |
- PowerSupply |
| 13 |
idrac_gather_facts_uri_method: "GET" |
| 14 |
idrac_gather_facts_uri_headers: |
| 15 |
Accept: "application/json" |
| 16 |
Content-Type: "application/json" |
| 17 |
OData-Version: "4.0" |
| 18 |
idrac_gather_facts_uri_body_format: "json" |
| 19 |
idrac_gather_facts_uri_status_code: |
| 20 |
- 200 |
| 21 |
- 400 |
| 22 |
- 401 |
| 23 |
- 404 |
| 24 |
- -1 |
| 25 |
idrac_gather_facts_uri_return_content: true |
| 26 |
diff_data: {} |
| 27 |
exclude_keys: ["LastUpdateTime"] |
| 28 |
power_supply_api: "/PowerSubsystem/PowerSupplies?$expand=*($levels=1)" |
| 29 |
|
| 30 |
tasks: |
| 31 |
|
| 32 |
- name: Find the chassis API |
| 33 |
ansible.builtin.include_tasks: |
| 34 |
../../tests/asserts/_check_chassis_url.yml |
| 35 |
|
| 36 |
- name: Fetching Power Supply info |
| 37 |
ansible.builtin.uri: |
| 38 |
url: "https://{{ hostname }}{{ api_chassis }}{{ power_supply_api }}" |
| 39 |
validate_certs: "{{ validate_certs }}" |
| 40 |
ca_path: "{{ ca_path | default(omit) }}" |
| 41 |
method: "{{ idrac_gather_facts_uri_method }}" |
| 42 |
user: "{{ username }}" |
| 43 |
password: "{{ password }}" |
| 44 |
headers: "{{ idrac_gather_facts_uri_headers }}" |
| 45 |
body_format: "{{ idrac_gather_facts_uri_body_format }}" |
| 46 |
status_code: "{{ idrac_gather_facts_uri_status_code }}" |
| 47 |
return_content: "{{ idrac_gather_facts_uri_return_content }}" |
| 48 |
register: powersupply_result |
| 49 |
ignore_errors: true |
| 50 |
no_log: true |
| 51 |
|
| 52 |
- name: Set powersupply facts |
| 53 |
ansible.builtin.set_fact: |
| 54 |
api_response: |
| 55 |
"{{ powersupply_result.json.Members | |
| 56 |
ansible.utils.remove_keys(target=['@odata.context', |
| 57 |
'@odata.id', '@odata.type', '@odata.etag', |
| 58 |
'[email protected]', |
| 59 |
'[email protected]', '[email protected]']) }}" |
| 60 |
when: powersupply_result is defined and powersupply_result.status == 200 |
| 61 |
|
| 62 |
- name: Gather Facts for the Power Supply component |
| 63 |
ansible.builtin.include_role: |
| 64 |
name: "idrac_gather_facts" |
| 65 |
|
| 66 |
- name: Assert power supply data |
| 67 |
ansible.builtin.assert: |
| 68 |
that: |
| 69 |
- "((api_response | length == 0) and (power_supply | length == 0))" |
| 70 |
fail_msg: "The response from the role does not match" |
| 71 |
success_msg: "The response from the role matches" |
| 72 |
when: api_response is defined and api_response | length == 0 |
| 73 |
|
| 74 |
- name: Removing dynamic values |
| 75 |
ansible.builtin.set_fact: |
| 76 |
power_supply: "{{ power_supply | ansible.utils.remove_keys(target= |
| 77 |
exclude_keys) }}" |
| 78 |
api_response: "{{ api_response | ansible.utils.remove_keys(target= |
| 79 |
exclude_keys) }}" |
| 80 |
|
| 81 |
- name: Check whether output differs |
| 82 |
ansible.builtin.set_fact: |
| 83 |
result_diff: "{{ power_supply | symmetric_difference(api_response) }}" |
| 84 |
when: api_response is defined and api_response | length > 0 |
| 85 |
|
| 86 |
- name: Assert the differences in List |
| 87 |
ansible.builtin.assert: |
| 88 |
fail_msg: "The response from the role does not match" |
| 89 |
success_msg: "The response from the role matches" |
| 90 |
that: |
| 91 |
- (result_diff | length) == 0 |
| 92 |
when: api_response is defined and api_response | length > 0 |