| 1 |
--- |
| 2 |
- name: Get Power Supply information. |
| 3 |
ansible.builtin.uri: |
| 4 |
url: "https://{{ hostname }}:{{ https_port }}{{ api_chassis }}/PowerSubsystem/PowerSupplies?$expand=*($levels=1)" |
| 5 |
register: power_result |
| 6 |
ignore_errors: true |
| 7 |
delegate_to: "{{ idrac_gather_facts_delegate }}" |
| 8 |
|
| 9 |
- name: Get Power Supply Metrics ids |
| 10 |
ansible.builtin.set_fact: |
| 11 |
power_metrics_ids: "{{ power_result.json.Members | selectattr('Metrics', 'defined') | map(attribute='Metrics') | flatten }}" |
| 12 |
when: power_result.status == 200 |
| 13 |
|
| 14 |
- name: Get Power Supply Metrics information. |
| 15 |
ansible.builtin.uri: |
| 16 |
url: "https://{{ hostname }}:{{ https_port }}{{ item['@odata.id'] }}" |
| 17 |
validate_certs: "{{ validate_certs }}" |
| 18 |
method: "{{ idrac_gather_facts_uri_method }}" |
| 19 |
user: "{{ username | default(lookup('env', 'IDRAC_USERNAME')) }}" |
| 20 |
password: "{{ password | default(lookup('env', 'IDRAC_PASSWORD')) }}" |
| 21 |
timeout: "{{ https_timeout }}" |
| 22 |
force_basic_auth: true |
| 23 |
headers: "{{ idrac_gather_facts_uri_headers }}" |
| 24 |
body_format: "{{ idrac_gather_facts_uri_body_format }}" |
| 25 |
status_code: "{{ idrac_gather_facts_uri_status_code }}" |
| 26 |
return_content: "{{ idrac_gather_facts_uri_return_content }}" |
| 27 |
loop: "{{ power_metrics_ids }}" |
| 28 |
when: power_result.status == 200 |
| 29 |
register: power_metrics_result |
| 30 |
delegate_to: "{{ idrac_gather_facts_delegate }}" |
| 31 |
|
| 32 |
- name: Get Thermal Metrics information. |
| 33 |
ansible.builtin.uri: |
| 34 |
url: "https://{{ hostname }}:{{ https_port }}{{ api_chassis }}/ThermalSubsystem/ThermalMetrics" |
| 35 |
validate_certs: "{{ validate_certs }}" |
| 36 |
method: "{{ idrac_gather_facts_uri_method }}" |
| 37 |
user: "{{ username | default(lookup('env', 'IDRAC_USERNAME')) }}" |
| 38 |
password: "{{ password | default(lookup('env', 'IDRAC_PASSWORD')) }}" |
| 39 |
timeout: "{{ https_timeout }}" |
| 40 |
force_basic_auth: true |
| 41 |
headers: "{{ idrac_gather_facts_uri_headers }}" |
| 42 |
body_format: "{{ idrac_gather_facts_uri_body_format }}" |
| 43 |
status_code: "{{ idrac_gather_facts_uri_status_code }}" |
| 44 |
return_content: "{{ idrac_gather_facts_uri_return_content }}" |
| 45 |
register: thermal_result |
| 46 |
delegate_to: "{{ idrac_gather_facts_delegate }}" |
| 47 |
|
| 48 |
- name: Get Memory information. |
| 49 |
ansible.builtin.uri: |
| 50 |
url: "https://{{ hostname }}:{{ https_port }}{{ api_system }}/Memory?$expand=*($levels=1)" |
| 51 |
validate_certs: "{{ validate_certs }}" |
| 52 |
method: "{{ idrac_gather_facts_uri_method }}" |
| 53 |
user: "{{ username | default(lookup('env', 'IDRAC_USERNAME')) }}" |
| 54 |
password: "{{ password | default(lookup('env', 'IDRAC_PASSWORD')) }}" |
| 55 |
headers: "{{ idrac_gather_facts_uri_headers }}" |
| 56 |
timeout: "{{ https_timeout }}" |
| 57 |
force_basic_auth: true |
| 58 |
body_format: "{{ idrac_gather_facts_uri_body_format }}" |
| 59 |
status_code: "{{ idrac_gather_facts_uri_status_code }}" |
| 60 |
return_content: "{{ idrac_gather_facts_uri_return_content }}" |
| 61 |
register: memory_result |
| 62 |
delegate_to: "{{ idrac_gather_facts_delegate }}" |
| 63 |
|
| 64 |
- name: Get Memory Metrics ids |
| 65 |
ansible.builtin.set_fact: |
| 66 |
memory_metrics_ids: "{{ memory_result.json.Members | selectattr('Metrics', 'defined') | map(attribute='Metrics') | flatten }}" |
| 67 |
when: memory_result.status == 200 |
| 68 |
|
| 69 |
- name: Get Memory Metrics information. |
| 70 |
ansible.builtin.uri: |
| 71 |
url: "https://{{ hostname }}:{{ https_port }}{{ item['@odata.id'] }}" |
| 72 |
validate_certs: "{{ validate_certs }}" |
| 73 |
ca_path: "{{ ca_path | default(omit) }}" |
| 74 |
method: "{{ idrac_gather_facts_uri_method }}" |
| 75 |
user: "{{ username | default(lookup('env', 'IDRAC_USERNAME')) }}" |
| 76 |
password: "{{ password | default(lookup('env', 'IDRAC_PASSWORD')) }}" |
| 77 |
timeout: "{{ https_timeout }}" |
| 78 |
force_basic_auth: true |
| 79 |
headers: "{{ idrac_gather_facts_uri_headers }}" |
| 80 |
body_format: "{{ idrac_gather_facts_uri_body_format }}" |
| 81 |
status_code: "{{ idrac_gather_facts_uri_status_code }}" |
| 82 |
return_content: "{{ idrac_gather_facts_uri_return_content }}" |
| 83 |
loop: "{{ memory_metrics_ids }}" |
| 84 |
when: memory_result.status == 200 |
| 85 |
register: memory_metrics_result |
| 86 |
delegate_to: "{{ idrac_gather_facts_delegate }}" |
| 87 |
|
| 88 |
- name: Set Power Supply facts |
| 89 |
ansible.builtin.set_fact: |
| 90 |
power_metrics: |
| 91 |
"{{ power_metrics_result.results | selectattr('json', 'defined') | map(attribute='json') | flatten | |
| 92 |
ansible.utils.remove_keys(target=['@odata.context', |
| 93 |
'@odata.type', '@odata.id', '@odata.etag', 'DataSourceUri']) }}" |
| 94 |
when: power_result.status == 200 |
| 95 |
|
| 96 |
- name: Set Thermal Metrics facts |
| 97 |
ansible.builtin.set_fact: |
| 98 |
thermal_metrics: |
| 99 |
"{{ thermal_result.json | ansible.utils.remove_keys(target=[ |
| 100 |
'@odata.context', '@odata.type', '@odata.id', '@odata.etag', |
| 101 |
'DataSourceUri', '[email protected]']) }}" |
| 102 |
when: thermal_result.status == 200 |
| 103 |
|
| 104 |
- name: Set Memory Metrics facts |
| 105 |
ansible.builtin.set_fact: |
| 106 |
memory_metrics: |
| 107 |
"{{ memory_metrics_result.results | selectattr('json', 'defined') | map(attribute='json') | flatten | |
| 108 |
ansible.utils.remove_keys(target=['@odata.context', |
| 109 |
'@odata.type', '@odata.id', '@odata.etag', 'DataSourceUri']) }}" |
| 110 |
when: memory_result.status == 200 |
| 111 |
|
| 112 |
- name: Error capture |
| 113 |
ansible.builtin.include_tasks: |
| 114 |
file: ./__capture_error.yml |
| 115 |
vars: |
| 116 |
register_vars: |
| 117 |
- "{{ power_result }}" |
| 118 |
- "{{ power_metrics_result }}" |
| 119 |
- "{{ thermal_result }}" |
| 120 |
- "{{ memory_result }}" |
| 121 |
- "{{ memory_metrics_result }}" |
| 122 |
component: 'systemmetrics' |