0

I have this playbook that what I'm trying to do it's to install CentOS using Ansible and Redfish, I don't want to use any modules, I'll install the CentOS on multiple Dell iDRAC9 servers and I'm having one issue:

2)After the ISO it's mounted, the server has not entered automatically into ISO boot menu, and I'm trying to achieve this by the Set ISO as primary boot device task.

Can someone please help me to correct this?

Here's the code:

- hosts: Linux_OS_machine
  connection: local
  name: ULP image install
  gather_facts: false
  vars:
    ansible_python_interpreter: /usr/bin/env python
    datatype: SetBiosAttributes
    image: "{{ iso_version }}-{{ inventory_hostname }}.iso"

  tasks:
    - name: Check system power state
      uri:
        url: https://{{ idrac }}/redfish/v1/Systems/System.Embedded.1
        user: "{{ idrac_user }}"
        password: "{{ idrac_pass }}"
        method: GET
        validate_certs: false
        force_basic_auth: yes
        return_content: yes
      register: system_status

    - name: Power on system if off
      when: system_status.json.PowerState == "Off"
      uri:
        url: https://{{ idrac }}/redfish/v1/Systems/System.Embedded.1/Actions/ComputerSystem.Reset/
        user: "{{ idrac_user }}"
        password: "{{ idrac_pass }}"
        method: POST
        body:
          ResetType: PushPowerButton  # Set ResetType to PushPowerButton for system poweron
        validate_certs: false
        force_basic_auth: yes
        status_code: 204
        body_format: json
      register: poweron_status

    - name: Check if virtual media is mounted
      uri:
        url: https://{{ idrac }}/redfish/v1/Managers/iDRAC.Embedded.1/VirtualMedia/CD
        user: "{{ idrac_user }}"
        password: "{{ idrac_pass }}"
        method: GET
        validate_certs: false
        force_basic_auth: yes
        return_content: yes
      register: vm_status

    - name: Unmount virtual media if mounted
      uri:
        url: https://{{ idrac }}/redfish/v1/Managers/iDRAC.Embedded.1/VirtualMedia/CD/Actions/VirtualMedia.EjectMedia
        method: POST
        user: "{{ idrac_user }}"
        password: "{{ idrac_pass }}"
        validate_certs: false
        force_basic_auth: yes
        status_code: 204
        body_format: json
      vars:
        image: "{{ iso_version }}-{{ inventory_hostname }}.iso"
      when:
        - vm_status.json.ConnectedVia == "VirtualMedia"
        - vm_status.json.Status != "NotConnected"
        - vm_status.json.Image != image

    - name: Mount virtual media if not already mounted
      uri:
        url: https://{{ idrac }}/redfish/v1/Managers/iDRAC.Embedded.1/VirtualMedia/CD/Actions/VirtualMedia.InsertMedia
        method: POST
        headers:
          Authorization: Basic {{ (idrac_user + ':' + idrac_pass) | b64encode }}
        user: "{{ idrac_user }}"
        password: "{{ idrac_pass }}"
        validate_certs: false
        force_basic_auth: yes
        status_code: [200, 204]
        body_format: json
        body:
          Image: ""
      vars:
        image: "{{ iso_version }}-{{ inventory_hostname }}.iso"
      register: mount_media
      when:
        - vm_status.json.ConnectedVia == "NotConnected"

    - name: Set ISO as primary boot device
      uri:
        url: https://{{ idrac }}/redfish/v1/Systems/System.Embedded.1
        method: PATCH
        headers:
          Authorization: Basic {{ (idrac_user + ':' + idrac_pass) | b64encode }}
          Content-Type: application/json
        user: "{{ idrac_user }}"
        password: "{{ idrac_pass }}"
        validate_certs: false
        force_basic_auth: yes
        status_code: [200, 204]
        body_format: json
        body:
          Boot:
            BootSourceOverrideTarget: Cd
            BootSourceOverrideEnabled: Once
            BootSourceOverrideSupported: ["None", "Cd", "Floppy", "Hdd", "Usb", "Pxe", "BiosSetup", "Utilities", "Diags", "SDCard", "UefiShell"]
            BootSourceOverrideMode: Legacy
            BootSourceOverrideTarget@odata.type: "#ComputerSystem.BootSource"


    - name: Reboot the system
      uri:
        url: https://{{ idrac }}/redfish/v1/Systems/System.Embedded.1/Actions/ComputerSystem.Reset/
        user: "{{ idrac_user }}"
        password: "{{ idrac_pass }}"
        method: POST
        body:
          ResetType: ForceRestart
        validate_certs: false
        force_basic_auth: yes
        status_code: 204
        body_format: json


    - name: Display message during ULP image installation
      debug:
        msg: "ULP image installation in progress. Please wait."



    - name: Wait for system to boot up
      wait_for:
        port: 22
        host: "{{ inventory_hostname }}"
        delay: 30
        timeout: 14400
        
    - name: Unmount ISO from server
      uri:
        url: https://{{ idrac }}/redfish/v1/Managers/iDRAC.Embedded.1/VirtualMedia/CD/Actions/VirtualMedia.EjectMedia
        method: POST
        user: "{{ idrac_user }}"
        password: "{{ idrac_pass }}"
        validate_certs: false
        force_basic_auth: yes
        status_code: 204
        body_format: json
      when: inventory_hostname in groups['Linux_OS_machine'] and "linux" in ansible_facts['os_family']
bicanul123
  • 101
  • 2
  • Do you have ISO uploaded in each idrac? – Romeo Ninov Apr 22 '23 at 18:21
  • it's on a remote server, the problem it's not the iso location it's the Mount virtual media if not already mounted function at the when case – bicanul123 Apr 22 '23 at 18:24
  • 1
    AFAIK the ISO **must** be uploaded in idrac to be available locally. And I do not see any part of ansible script to do this upload. – Romeo Ninov Apr 22 '23 at 18:57
  • The task - name: Mount virtual media if not already mounted it's mounting the ISO in the virtual console, however, if the ISO it's mounted then the playbook fails because of the iDRAC reporting that an ISO it's mounted already – bicanul123 Apr 22 '23 at 19:01
  • (Legally required notice - I work for Dell) I’m curious - what is driving you to do this through API endpoints manually instead of using https://docs.ansible.com/ansible/latest/collections/dellemc/openmanage/idrac_os_deployment_module.html – Grant Curell Apr 23 '23 at 09:27
  • Recommendation: you should also never use a static wait in Ansible (for servers or otherwise) and then assume something has happened after some fixed time. In this case, updates, BIOS changes, someone asks for a memcheck, etc will all break that code. You want to trigger the reboot and then wait for whatever specific condition you expect to see before continuing. – Grant Curell Apr 23 '23 at 09:36
  • @GrantCurell because I don't have internet connection to install the dellemc.openmanage.idrac_os_deployment module so I'm forced to use the Redfish API... I've managed to do something, I've updated the code, however, I'm encountering this now: ,,the resource /redfish/v1/Systems/System.Embedded.1/BootSettings entered is not found". I've tried to contact Dell directly but idk who can help me and where should I get the assistance – bicanul123 Apr 23 '23 at 09:41
  • @robi10101298 you're pretty far off the normal path. Dell's support will address bugs and standard tech support questions but isn't going to do much when it comes to reverse engineering Dell's redfish implementation. You can explore what's at a given REST API endpoint (Dell or otherwise) by browsing to it. In this case "https:///redfish/v1/Systems/System.Embedded.1/". If this is a government SCIF or some such thing my recommendation is you just pull the official modules and sneakernet them in. I would just install them in a container somewhere with Internet and then walk the container – Grant Curell Apr 23 '23 at 12:20
  • to wherever you don't have internet. That's going to take a tiny fraction of the time it will be to create a custom framework. You'll bump into a few issues you'll have to work through but it will be way way way... way less painful than trying to do this all custom. (In the case of some sort of secure facility government or otherwise, far less time in approvals than it's going to take in re-engineering) – Grant Curell Apr 23 '23 at 12:21
  • @GrantCurell I've achieved making the installation to boot from the ISO, now I'm struggling to get it to unmount after the system it's restarted, so I can say that I progressed :) I've updated once again the code, thanks again for your help and recommendations! – bicanul123 Apr 23 '23 at 12:33

1 Answers1

0

I have been able to accomplish an OS Deployment to iDRAC9 using the dellemc.openmanage collection. Add the collection via ansible galaxy commands then from a playbook, import the role dellemc.openmanage.idrac_os_deployment. https://github.com/dell/dellemc-openmanage-ansible-modules/blob/collections/playbooks/idrac/idrac_os_deployment.yml

If you haven't figured it out yet, I can work on putting my project into Gitlab to give you an idea of what to do. Let me know

ma1band
  • 1
  • 1