|
| 1 | +# SPDX-License-Identifier: Apache-2.0 |
| 2 | +--- |
| 3 | +- name: Run OS installation on servers |
| 4 | + hosts: dh1bmc, dh4bmc |
| 5 | + gather_facts: true |
| 6 | + vars: |
| 7 | + ansible_python_interpreter: "/root/.local/share/pipx/venvs/omsdk/bin/python" |
| 8 | + validate_certs: false |
| 9 | + osd_service_url: "/redfish/v1/Systems/System.Embedded.1/Oem/Dell/DellOSDeploymentService" |
| 10 | + |
| 11 | + tasks: |
| 12 | + - name: Get ISO image attach status |
| 13 | + block: |
| 14 | + - name: Get ISO attach status |
| 15 | + ansible.builtin.uri: |
| 16 | + url: "https://{{ ansible_host }}{{ osd_service_url }}/Actions/DellOSDeploymentService.GetAttachStatus" |
| 17 | + user: "{{ ansible_user }}" |
| 18 | + password: "{{ ansible_password }}" |
| 19 | + method: POST |
| 20 | + headers: |
| 21 | + Accept: "application/json" |
| 22 | + Content-Type: "application/json" |
| 23 | + OData-Version: "4.0" |
| 24 | + body: "{}" |
| 25 | + status_code: 200 |
| 26 | + validate_certs: false |
| 27 | + force_basic_auth: true |
| 28 | + register: attach_status |
| 29 | + delegate_to: localhost |
| 30 | + |
| 31 | + - name: Set ISO attach status as a fact variable |
| 32 | + ansible.builtin.set_fact: |
| 33 | + idrac_iso_attach_status: "{{ idrac_iso_attach_status | default({}) | combine({item.key: item.value}) }}" |
| 34 | + with_dict: |
| 35 | + drivers_attach_status: "{{ attach_status.json.DriversAttachStatus }}" |
| 36 | + iso_attach_status: "{{ attach_status.json.ISOAttachStatus }}" |
| 37 | + |
| 38 | + - name: Detatch ISO image if attached |
| 39 | + when: |
| 40 | + - idrac_iso_attach_status |
| 41 | + - idrac_iso_attach_status.iso_attach_status == "Attached" or idrac_iso_attach_status.drivers_attach_status == "Attached" |
| 42 | + block: |
| 43 | + - name: Detach ISO image if attached |
| 44 | + ansible.builtin.uri: |
| 45 | + url: "https://{{ ansible_host }}{{ osd_service_url }}/Actions/DellOSDeploymentService.DetachISOImage" |
| 46 | + user: "{{ ansible_user }}" |
| 47 | + password: "{{ ansible_password }}" |
| 48 | + method: POST |
| 49 | + headers: |
| 50 | + Accept: "application/json" |
| 51 | + Content-Type: "application/json" |
| 52 | + OData-Version: "4.0" |
| 53 | + body: "{}" |
| 54 | + status_code: 200 |
| 55 | + validate_certs: false |
| 56 | + force_basic_auth: true |
| 57 | + register: detach_status |
| 58 | + delegate_to: localhost |
| 59 | + |
| 60 | + - name: Print a message |
| 61 | + ansible.builtin.debug: |
| 62 | + msg: "Successfuly detached the ISO image" |
| 63 | + |
| 64 | + - name: Install Ubuntu OS |
| 65 | + ansible.builtin.import_role: |
| 66 | + name: dellemc.openmanage.idrac_os_deployment |
| 67 | + vars: |
| 68 | + hostname: "{{ ansible_host }}" |
| 69 | + username: root |
| 70 | + password: "{{ ansible_password }}" |
| 71 | + os_name: RHEL |
| 72 | + os_version: 9 |
| 73 | + # currently only RHEL is supported, we are working to add support for UBUNTU |
| 74 | + # Here is the issue we have opened for the feature request: https://github.com/dell/dellemc-openmanage-ansible-modules/issues/780 |
| 75 | + source: |
| 76 | + protocol: http |
| 77 | + hostname: "{{ hostvars['mgmt']['ansible_host'] }}" |
| 78 | + iso_path: "" |
| 79 | + iso_name: ubuntu-22.04-autoinstall.iso |
| 80 | + is_custom_iso: true |
0 commit comments