---
- hosts: idrac
  connection: local
  name: Dell OpenManage Ansible iDRAC Redfish Storage Controller service.
  gather_facts: False

  collections:
    - dellemc.openmanage

  tasks:
  - name: Assign dedicated hot spare.
    idrac_redfish_storage_controller:
      baseuri: "{{ baseuri }}"
      username: "{{ username }}"
      password: "{{ password }}"
      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

  - name: Assign global hot spare.
    idrac_redfish_storage_controller:
      baseuri: "{{ baseuri }}"
      username: "{{ username }}"
      password: "{{ password }}"
      target: "Disk.Bay.0:Enclosure.Internal.0-1:RAID.Slot.1-1"
    tags:
      - assign_global_hot_spare

  - name: Set controller encryption key.
    idrac_redfish_storage_controller:
      baseuri: "{{ baseuri }}"
      username: "{{ username }}"
      password: "{{ password }}"
      command: "SetControllerKey"
      controller_id: "RAID.Slot.1-1"
      key: "PassPhrase@123"
      key_id: "mykeyid123"
    tags:
      - set_controller_key

  - name: Rekey in LKM mode.
    idrac_redfish_storage_controller:
      baseuri: "{{ baseuri }}"
      username: "{{ username }}"
      password: "{{ password }}"
      command: "ReKey"
      controller_id: "RAID.Slot.1-1"
      key: "NewPassPhrase@123"
      key_id: "newkeyid123"
      old_key: "OldPassPhrase@123"
    tags:
      - rekey_lkm

  - name: Rekey in SEKM mode.
    idrac_redfish_storage_controller:
      baseuri: "{{ baseuri }}"
      username: "{{ username }}"
      password: "{{ password }}"
      command: "ReKey"
      controller_id: "RAID.Slot.1-1"
      mode: "SEKM"
    tags:
      - rekey_sekm

  - name: Remove controller key.
    idrac_redfish_storage_controller:
      baseuri: "{{ baseuri }}"
      username: "{{ username }}"
      password: "{{ password }}"
      command: "RemoveControllerKey"
      controller_id: "RAID.Slot.1-1"
    tags:
      - remove_controller_key

  - name: Reset controller configuration.
    idrac_redfish_storage_controller:
      baseuri: "{{ baseuri }}"
      username: "{{ username }}"
      password: "{{ password }}"
      command: "ResetConfig"
      controller_id: "RAID.Slot.1-1"
    tags:
      - reset_config