---
- name: Dell OpenManage Ansible iDRAC Redfish Storage Controller service.
  hosts: idrac
  gather_facts: false

  tasks:
    - name: Assign dedicated hot spare.
      dellemc.openmanage.idrac_redfish_storage_controller:
        baseuri: "{{ baseuri }}"
        username: "{{ username }}"
        password: "{{ password }}"
        command: "AssignSpare"
        ca_path: "/path/to/ca_cert.pem"
        volume_id:
          - "Disk.Virtual.0:RAID.Slot.1-1"
        target: "Disk.Bay.0:Enclosure.Internal.0-1:RAID.Slot.1-1"
      tags:
        - assign_dedicated_hot_spare
      delegate_to: localhost

    - name: Assign global hot spare.
      dellemc.openmanage.idrac_redfish_storage_controller:
        baseuri: "{{ baseuri }}"
        username: "{{ username }}"
        password: "{{ password }}"
        command: "AssignSpare"
        ca_path: "/path/to/ca_cert.pem"
        target: "Disk.Bay.0:Enclosure.Internal.0-1:RAID.Slot.1-1"
      tags:
        - assign_global_hot_spare
      delegate_to: localhost

    - name: Unassign hot spare
      dellemc.openmanage.idrac_redfish_storage_controller:
        baseuri: "{{ baseuri }}"
        username: "{{ username }}"
        password: "{{ password }}"
        ca_path: "/path/to/ca_cert.pem"
        target: "Disk.Bay.0:Enclosure.Internal.0-1:RAID.Slot.1-1"
        command: UnassignSpare
      tags:
        - un-assign-hot-spare
      delegate_to: localhost

    - name: Set controller encryption key.
      dellemc.openmanage.idrac_redfish_storage_controller:
        baseuri: "{{ baseuri }}"
        username: "{{ username }}"
        password: "{{ password }}"
        ca_path: "/path/to/ca_cert.pem"
        command: "SetControllerKey"
        controller_id: "RAID.Slot.1-1"
        key: "PassPhrase@123"
        key_id: "mykeyid123"
      tags:
        - set_controller_key
      delegate_to: localhost

    - name: Rekey in LKM mode.
      dellemc.openmanage.idrac_redfish_storage_controller:
        baseuri: "{{ baseuri }}"
        username: "{{ username }}"
        password: "{{ password }}"
        ca_path: "/path/to/ca_cert.pem"
        command: "ReKey"
        controller_id: "RAID.Slot.1-1"
        key: "NewPassPhrase@123"
        key_id: "newkeyid123"
        old_key: "OldPassPhrase@123"
      tags:
        - rekey_lkm
      delegate_to: localhost

    - name: Rekey in SEKM mode.
      dellemc.openmanage.idrac_redfish_storage_controller:
        baseuri: "{{ baseuri }}"
        username: "{{ username }}"
        password: "{{ password }}"
        ca_path: "/path/to/ca_cert.pem"
        command: "ReKey"
        controller_id: "RAID.Slot.1-1"
        mode: "SEKM"
      tags:
        - rekey_sekm
      delegate_to: localhost

    - name: Remove controller key.
      dellemc.openmanage.idrac_redfish_storage_controller:
        baseuri: "{{ baseuri }}"
        username: "{{ username }}"
        password: "{{ password }}"
        ca_path: "/path/to/ca_cert.pem"
        command: "RemoveControllerKey"
        controller_id: "RAID.Slot.1-1"
      tags:
        - remove_controller_key
      delegate_to: localhost

    - name: Reset controller configuration.
      dellemc.openmanage.idrac_redfish_storage_controller:
        baseuri: "{{ baseuri }}"
        username: "{{ username }}"
        password: "{{ password }}"
        ca_path: "/path/to/ca_cert.pem"
        command: "ResetConfig"
        controller_id: "RAID.Slot.1-1"
      tags:
        - reset_config
      delegate_to: localhost

    - name: Enable controller encryption
      dellemc.openmanage.idrac_redfish_storage_controller:
        baseuri: "{{ baseuri }}"
        username: "{{ username }}"
        password: "{{ password }}"
        ca_path: "/path/to/ca_cert.pem"
        command: "EnableControllerEncryption"
        controller_id: "RAID.Slot.1-1"
        mode: "LKM"
        key: "your_Key@123"
        key_id: "your_Keyid@123"
      tags:
        - enable-encrypt
      delegate_to: localhost

    - name: Blink physical disk.
      dellemc.openmanage.idrac_redfish_storage_controller:
        baseuri: "{{ baseuri }}"
        username: "{{ username }}"
        password: "{{ password }}"
        ca_path: "/path/to/ca_cert.pem"
        command: "BlinkTarget"
        target: "Disk.Bay.0:Enclosure.Internal.0-1:RAID.Slot.1-1"
      tags:
        - blink-target
      delegate_to: localhost

    - name: Blink virtual drive.
      dellemc.openmanage.idrac_redfish_storage_controller:
        baseuri: "{{ baseuri }}"
        username: "{{ username }}"
        password: "{{ password }}"
        ca_path: "/path/to/ca_cert.pem"
        command: "BlinkTarget"
        volume_id: "Disk.Virtual.0:RAID.Slot.1-1"
      tags:
        - blink-volume
      delegate_to: localhost

    - name: Unblink physical disk.
      dellemc.openmanage.idrac_redfish_storage_controller:
        baseuri: "{{ baseuri }}"
        username: "{{ username }}"
        password: "{{ password }}"
        ca_path: "/path/to/ca_cert.pem"
        command: "UnBlinkTarget"
        target: "Disk.Bay.0:Enclosure.Internal.0-1:RAID.Slot.1-1"
      tags:
        - unblink-target
      delegate_to: localhost

    - name: Unblink virtual drive.
      dellemc.openmanage.idrac_redfish_storage_controller:
        baseuri: "{{ baseuri }}"
        username: "{{ username }}"
        password: "{{ password }}"
        ca_path: "/path/to/ca_cert.pem"
        command: "UnBlinkTarget"
        volume_id: "Disk.Virtual.0:RAID.Slot.1-1"
      tags:
        - unblink-drive
      delegate_to: localhost

    - name: Convert physical disk to RAID
      dellemc.openmanage.idrac_redfish_storage_controller:
        baseuri: "{{ baseuri }}"
        username: "{{ username }}"
        password: "{{ password }}"
        ca_path: "/path/to/ca_cert.pem"
        command: "ConvertToRAID"
        target: "Disk.Bay.0:Enclosure.Internal.0-1:RAID.Slot.1-1"
      tags:
        - convert-raid
      delegate_to: localhost

    - name: Convert physical disk to non-RAID
      dellemc.openmanage.idrac_redfish_storage_controller:
        baseuri: "{{ baseuri }}"
        username: "{{ username }}"
        password: "{{ password }}"
        ca_path: "/path/to/ca_cert.pem"
        command: "ConvertToNonRAID"
        target: "Disk.Bay.0:Enclosure.Internal.0-1:RAID.Slot.1-1"
      tags:
        - convert-non-raid
      delegate_to: localhost

    - name: Change physical disk state to online.
      dellemc.openmanage.idrac_redfish_storage_controller:
        baseuri: "{{ baseuri }}"
        username: "{{ username }}"
        password: "{{ password }}"
        ca_path: "/path/to/ca_cert.pem"
        command: "ChangePDStateToOnline"
        target: "Disk.Bay.1:Enclosure.Internal.0-1:RAID.Slot.1-1"
      tags:
        - pd-state-online
      delegate_to: localhost

    - name: Change physical disk state to offline.
      dellemc.openmanage.idrac_redfish_storage_controller:
        baseuri: "{{ baseuri }}"
        username: "{{ username }}"
        password: "{{ password }}"
        ca_path: "/path/to/ca_cert.pem"
        command: "ChangePDStateToOnline"
        target: "Disk.Bay.1:Enclosure.Internal.0-1:RAID.Slot.1-1"
      tags:
        - pd-state-offline
      delegate_to: localhost

    - name: Lock virtual drive
      dellemc.openmanage.idrac_redfish_storage_controller:
        baseuri: "{{ baseuri }}"
        username: "{{ username }}"
        password: "{{ password }}"
        ca_path: "/path/to/ca_cert.pem"
        command: "LockVirtualDisk"
        volume_id: "Disk.Virtual.0:RAID.SL.3-1"
      tags:
        - lock
      delegate_to: localhost

    - name: Online Capacity Expansion of a volume using target
      dellemc.openmanage.idrac_redfish_storage_controller:
        baseuri: "{{ baseuri }}"
        username: "{{ username }}"
        password: "{{ password }}"
        ca_path: "/path/to/ca_cert.pem"
        command: "OnlineCapacityExpansion"
        volume_id: "Disk.Virtual.0:RAID.Integrated.1-1"
        target:
          - "Disk.Bay.3:Enclosure.Internal.0-0:RAID.Integrated.1-1"
      tags:
        - oce_target
      delegate_to: localhost

    - name: Online Capacity Expansion of a volume using size
      dellemc.openmanage.idrac_redfish_storage_controller:
        baseuri: "{{ baseuri }}"
        username: "{{ username }}"
        password: "{{ password }}"
        ca_path: "/path/to/ca_cert.pem"
        command: "OnlineCapacityExpansion"
        volume_id: "Disk.Virtual.0:RAID.Integrated.1-1"
        size: 363786
      tags:
        - oce_size
      delegate_to: localhost

    - name: Set controller attributes.
      dellemc.openmanage.idrac_redfish_storage_controller:
        baseuri: "{{ baseuri }}"
        username: "{{ username }}"
        password: "{{ password }}"
        ca_path: "/path/to/ca_cert.pem"
        controller_id: "RAID.Slot.1-1"
        attributes:
          ControllerMode: "HBA"
        apply_time: "OnReset"
      tags:
        - controller
      delegate_to: localhost

    - name: Configure Controller attributes at Maintenance window
      dellemc.openmanage.idrac_redfish_storage_controller:
        baseuri: "{{ baseuri }}"
        username: "{{ username }}"
        password: "{{ password }}"
        ca_path: "/path/to/ca_cert.pem"
        controller_id: "RAID.Slot.1-1"
        attributes:
          CheckConsistencyMode: Normal
          CopybackMode: "Off"
          LoadBalanceMode: Disabled
        apply_time: AtMaintenanceWindowStart
        maintenance_window:
          start_time: "2022-09-30T05:15:40-05:00"
          duration: 1200
      delegate_to: localhost

    - name: Perform Secure Erase operation on SED drive
      dellemc.openmanage.idrac_redfish_storage_controller:
        baseuri: "192.168.0.1:443"
        username: "user_name"
        password: "user_password"
        ca_path: "/path/to/ca_cert.pem"
        controller_id: "RAID.Slot.1-1"
        command: "SecureErase"
        target: "Disk.Bay.1:Enclosure.Internal.0-1:RAID.Slot.1-1"
      delegate_to: localhost
