| 1 |
--- |
| 2 |
- name: Ansible Module for Simple Firmware Update |
| 3 |
hosts: redfish_hosts |
| 4 |
gather_facts: false |
| 5 |
vars: |
| 6 |
retries_count: 100 |
| 7 |
polling_interval: 5 |
| 8 |
reboot_uri: "/redfish/v1/Systems/System.Embedded.1/Actions/ComputerSystem.Reset" |
| 9 |
|
| 10 |
tasks: |
| 11 |
- name: Update the firmware from a single executable file available in a HTTP protocol |
| 12 |
dellemc.openmanage.redfish_firmware: |
| 13 |
baseuri: "{{ baseuri }}" |
| 14 |
username: "{{ username }}" |
| 15 |
password: "{{ password }}" |
| 16 |
ca_path: "/path/to/ca_cert.pem" |
| 17 |
image_uri: "http://192.168.0.1/firmware_repo/component.exe" |
| 18 |
register: result |
| 19 |
delegate_to: localhost |
| 20 |
|
| 21 |
- name: Update the firmware from a single executable with job tracking till completion |
| 22 |
ansible.builtin.uri: |
| 23 |
url: "https://{{ baseuri }}{{ result.task.uri }}" |
| 24 |
user: "{{ username }}" |
| 25 |
password: "{{ password }}" |
| 26 |
method: "GET" |
| 27 |
use_proxy: true |
| 28 |
status_code: 200, 202 |
| 29 |
return_content: true |
| 30 |
validate_certs: false |
| 31 |
force_basic_auth: true |
| 32 |
headers: |
| 33 |
Content-Type: "application/json" |
| 34 |
Accept: "application/json" |
| 35 |
register: job_result |
| 36 |
until: job_result.json.TaskState == 'Completed' or job_result.json.TaskState == 'Pending' |
| 37 |
retries: "{{ retries_count }}" |
| 38 |
delay: "{{ polling_interval }}" |
| 39 |
delegate_to: localhost |
| 40 |
|
| 41 |
- name: Update the firmware from a single executable reboot. |
| 42 |
ansible.builtin.uri: |
| 43 |
url: "https://{{ baseuri }}{{ reboot_uri }}" |
| 44 |
user: "{{ username }}" |
| 45 |
password: "{{ password }}" |
| 46 |
method: "POST" |
| 47 |
body_format: raw |
| 48 |
body: '{"ResetType": "ForceRestart"}' |
| 49 |
use_proxy: true |
| 50 |
status_code: 204 |
| 51 |
return_content: false |
| 52 |
validate_certs: false |
| 53 |
force_basic_auth: true |
| 54 |
headers: |
| 55 |
Content-Type: "application/json" |
| 56 |
Accept: "application/json" |
| 57 |
register: reboot_result |
| 58 |
changed_when: reboot_result.status == 204 |
| 59 |
when: job_result.json.TaskState == 'Pending' and job_result.json.Messages.0.Message == 'Task successfully scheduled.' |
| 60 |
delegate_to: localhost |
| 61 |
|
| 62 |
- name: Update the firmware from a single executable Waits for 4 minutes. |
| 63 |
ansible.builtin.wait_for: |
| 64 |
timeout: 240 |
| 65 |
when: job_result.json.TaskState == 'Pending' and job_result.json.Messages.0.Message == 'Task successfully scheduled.' |
| 66 |
delegate_to: localhost |
| 67 |
|
| 68 |
- name: Update the firmware from a single executable with job tracking till completion. |
| 69 |
ansible.builtin.uri: |
| 70 |
url: "https://{{ baseuri }}{{ result.task.uri }}" |
| 71 |
user: "{{ username }}" |
| 72 |
password: "{{ password }}" |
| 73 |
method: "GET" |
| 74 |
use_proxy: true |
| 75 |
status_code: 200, 202 |
| 76 |
return_content: true |
| 77 |
validate_certs: false |
| 78 |
force_basic_auth: true |
| 79 |
headers: |
| 80 |
Content-Type: "application/json" |
| 81 |
Accept: "application/json" |
| 82 |
register: final_result |
| 83 |
until: final_result.json.TaskState == 'Completed' |
| 84 |
retries: "{{ retries_count }}" |
| 85 |
delay: "{{ polling_interval }}" |
| 86 |
delegate_to: localhost |
| 87 |
|
| 88 |
- name: Update the firmware from a single executable fact. |
| 89 |
ansible.builtin.set_fact: |
| 90 |
job_details: "{{ final_result.json }}" |
| 91 |
failed_when: final_result.json.TaskState == "Completed" and final_result.json.TaskStatus != "OK" |
| 92 |
changed_when: final_result.json.TaskState == "Completed" and final_result.json.TaskStatus == "OK" |