Home > Servers > Systems Management > White Papers > Dell PowerEdge: Getting Started with Redfish Ansible Modules > Operating system deployment
This section describes how to use Ansible and Redfish to automate operating system deployment on a PowerEdge server. The example shows how to connect the virtual media to the server and have the server boot from it.
Note: Details about the installation of the operating system and its automation are operating-system dependent and are outside the scope of this paper.
Note: The playbook assumes that an ISO file containing the operating system installer has been downloaded and is available on an NFS or CIFS share. Downloading the ISO file and the creation of the NFS share are outside the scope of this paper.
In our example, we boot from an Ubuntu installation ISO. We assume that each host entry in the inventory file includes the baseuri variable, pointing to the iDRAC IP address for each server. We also assume that each host entry in the inventory file includes idrac_user and idrac_password variables containing the credentials to authenticate against the iDRAC.
---
- hosts: labhosts
name: Install ubuntu 20.04.4
gather_facts: False
vars:
ansible_python_interpreter: "/usr/bin/env python3"
idrac_osd_command_allowable_values: ["BootToNetworkISO", "GetAttachStatus", "DetachISOImage"]
idrac_osd_command_default: "GetAttachStatus"
GetAttachStatus_Code:
DriversAttachStatus:
"0": "NotAttached"
"1": "Attached"
ISOAttachStatus:
"0": "NotAttached"
"1": "Attached"
idrac_https_port: 443
expose_duration: 1080
command: "{{ idrac_osd_command_default }}"
validate_certs: no
force_basic_auth: yes
share_name: nfsserver:/home/user1/share
ubuntu_iso: ubuntu-20.04.4-live-server-amd64.iso
collections:
- dellemc.openmanage
tasks:
- name: find the URL for the DellOSDeploymentService
ansible.builtin.uri:
url: "https://{{ baseuri }}/redfish/v1/Systems/System.Embedded.1"
user: "{{ idrac_user }}"
password: "{{ idrac_password }}"
method: GET
headers:
Accept: "application/json"
OData-Version: "4.0"
status_code: 200
validate_certs: "{{ validate_certs }}"
force_basic_auth: "{{ force_basic_auth }}"
register: result
delegate_to: localhost
- name: find the URL for the DellOSDeploymentService
ansible.builtin.set_fact:
idrac_osd_service_url: "{{ result.json.Links.Oem.Dell.DellOSDeploymentService['@odata.id'] }}"
when:
- result.json.Links.Oem.Dell.DellOSDeploymentService is defined
- block:
- name: get ISO attach status
ansible.builtin.uri:
url: "https://{{ baseuri }}{{ idrac_osd_service_url }}/Actions/DellOSDeploymentService.GetAttachStatus"
user: "{{ idrac_user }}"
password: "{{ idrac_password }}"
method: POST
headers:
Accept: "application/json"
Content-Type: "application/json"
OData-Version: "4.0"
body: "{}"
status_code: 200
validate_certs: "{{ validate_certs }}"
force_basic_auth: "{{ force_basic_auth }}"
register: attach_status
delegate_to: localhost
- name: set ISO attach status as a fact variable
ansible.builtin.set_fact:
idrac_iso_attach_status: "{{ idrac_iso_attach_status | default({}) | combine({item.key: item.value}) }}"
with_dict:
DriversAttachStatus: "{{ attach_status.json.DriversAttachStatus }}"
ISOAttachStatus: "{{ attach_status.json.ISOAttachStatus }}"
when:
- idrac_osd_service_url is defined
- idrac_osd_service_url|length > 0
- block:
- name: detach ISO image if attached
ansible.builtin.uri:
url: "https://{{ baseuri }}{{ idrac_osd_service_url }}/Actions/DellOSDeploymentService.DetachISOImage"
user: "{{ idrac_user }}"
password: "{{ idrac_password }}"
method: POST
headers:
Accept: "application/json"
Content-Type: "application/json"
OData-Version: "4.0"
body: "{}"
status_code: 200
validate_certs: "{{ validate_certs }}"
force_basic_auth: "{{ force_basic_auth }}"
register: detach_status
delegate_to: localhost
- ansible.builtin.debug:
msg: "Successfuly detached the ISO image"
when:
- idrac_osd_service_url is defined and idrac_osd_service_url|length > 0
- idrac_iso_attach_status
- idrac_iso_attach_status.ISOAttachStatus == "Attached" or
idrac_iso_attach_status.DriversAttachStatus == "Attached"
- name: boot to network ISO
dellemc.openmanage.idrac_os_deployment:
idrac_ip: "{{ baseuri }}"
idrac_user: "{{ idrac_user }}"
idrac_password: "{{ idrac_password }}"
share_name: "{{ share_name }}"
iso_image: "{{ ubuntu_iso }}"
expose_duration: "{{ expose_duration }}"
validate_certs: False
register: boot_to_network_iso_status
delegate_to: localhost
A dissection of this playbook, except for the self-explanatory variable section, follows:
- name: find the URL for the DellOSDeploymentService
ansible.builtin.uri:
url: "https://{{ baseuri }}/redfish/v1/Systems/System.Embedded.1"
user: "{{ idrac_user }}"
password: "{{ idrac_password }}"
method: GET
headers:
Accept: "application/json"
OData-Version: "4.0"
status_code: 200
validate_certs: "{{ validate_certs }}"
force_basic_auth: "{{ force_basic_auth }}"
register: result
delegate_to: localhost
- name: find the URL for the DellOSDeploymentService
ansible.builtin.set_fact:
idrac_osd_service_url: "{{ result.json.Links.Oem.Dell.DellOSDeploymentService['@odata.id'] }}"
when:
- result.json.Links.Oem.Dell.DellOSDeploymentService is defined
The first task is to get the Redfish URI for the operating system deployment service on the PowerEdge server. That URI is Dell specific, which is why it is in the OEM schema within Redfish. The URI is used in subsequent tasks to ascertain if an ISO image is already attached to the server.
- block:
- name: get ISO attach status
ansible.builtin.uri:
url: "https://{{ baseuri }}{{ idrac_osd_service_url }}/Actions/DellOSDeploymentService.GetAttachStatus"
user: "{{ idrac_user }}"
password: "{{ idrac_password }}"
method: POST
headers:
Accept: "application/json"
Content-Type: "application/json"
OData-Version: "4.0"
body: "{}"
status_code: 200
validate_certs: "{{ validate_certs }}"
force_basic_auth: "{{ force_basic_auth }}"
register: attach_status
delegate_to: localhost
- name: set ISO attach status as a fact variable
ansible.builtin.set_fact:
idrac_iso_attach_status: "{{ idrac_iso_attach_status | default({}) | combine({item.key: item.value}) }}"
with_dict:
DriversAttachStatus: "{{ attach_status.json.DriversAttachStatus }}"
ISOAttachStatus: "{{ attach_status.json.ISOAttachStatus }}"
when:
- idrac_osd_service_url is defined
- idrac_osd_service_url|length > 0
In this task, we use the URI found through task #1 to get the ISO attach status for the variable. To that end, we query the DellOSDeploymentService.GetAttachStatus endpoint and determine if an ISO image is already attached.
- block:
- name: detach ISO image if attached
ansible.builtin.uri:
url: "https://{{ baseuri }}{{ idrac_osd_service_url }}/Actions/DellOSDeploymentService.DetachISOImage"
user: "{{ idrac_user }}"
password: "{{ idrac_password }}"
method: POST
headers:
Accept: "application/json"
Content-Type: "application/json"
OData-Version: "4.0"
body: "{}"
status_code: 200
validate_certs: "{{ validate_certs }}"
force_basic_auth: "{{ force_basic_auth }}"
register: detach_status
delegate_to: localhost
- ansible.builtin.debug:
msg: "Successfuly detached the ISO image"
when:
- idrac_osd_service_url is defined and idrac_osd_service_url|length > 0
- idrac_iso_attach_status
- idrac_iso_attach_status.ISOAttachStatus == "Attached" or
idrac_iso_attach_status.DriversAttachStatus == "Attached"
This task is optional but could be considered a safety measure. It detaches any ISO image that is already attached to the server, which ensures that the server does not boot from the wrong ISO image. In task #2, we created two facts (also known as variables): DriverAttachStatus and ISOAttachStatus. Task #3 runs only if the status of either of these variables is ‘Attached’, meaning that an image is already attached to the server. If an image is attached, we detach it because the next task attaches the required ISO to the server.
- name: boot to network ISO
dellemc.openmanage.idrac_os_deployment:
idrac_ip: "{{ baseuri }}"
idrac_user: "{{ idrac_user }}"
idrac_password: "{{ idrac_password }}"
share_name: "{{ share_name }}"
iso_image: "{{ ubuntu_iso }}"
expose_duration: "{{ expose_duration }}"
validate_certs: False
register: boot_to_network_iso_status
delegate_to: localhost
This task is where we boot the server from the ISO image. This task uses the dellemc.openmanage Ansible module. The idrac_os_deployment function within that module performs multiple actions on the iDRAC:
At the end of these tasks, the server boots from the ISO image and launches the operating system installer that is stored on the image. You can also use Ansible to automate operating system installation. That process is operating-system dependent and outside the scope of this paper.