---
- name: Dell OpenManage Ansible iDRAC Certificates management.
  hosts: idrac
  gather_facts: false

  tasks:
    - name: Generate https signing request
      dellemc.openmanage.idrac_certificates:
        idrac_ip: "{{ idrac_ip }}"
        idrac_user: "{{ idrac_user }}"
        idrac_password: "{{ idrac_password }}"
        ca_path: "/path/to/ca_cert.pem"
        command: "generate_csr"
        certificate_type: "HTTPS"
        certificate_path: "/home/omam/mycert_dir"
        cert_params:
          common_name: "sample.domain.com"
          organization_unit: "OrgUnit"
          locality_name: "Bangalore"
          state_name: "Karnataka"
          country_code: "IN"
          email_address: "admin@domain.com"
          organization_name: "OrgName"
          subject_alt_name:
            - 192.198.2.1
      delegate_to: localhost

    - name: Import a SSL certificate.
      dellemc.openmanage.idrac_certificates:
        idrac_ip: "{{ idrac_ip }}"
        idrac_user: "{{ idrac_user }}"
        idrac_password: "{{ idrac_password }}"
        ca_path: "/path/to/ca_cert.pem"
        command: "import"
        certificate_type: "HTTPS"
        certificate_path: "/path/to/cert.pem"
      delegate_to: localhost

    - name: Import an HTTPS certificate along with its private key.
      dellemc.openmanage.idrac_certificates:
        idrac_ip: "{{ idrac_ip }}"
        idrac_user: "{{ idrac_user }}"
        idrac_password: "{{ idrac_password }}"
        ca_path: "/path/to/ca_cert.pem"
        command: "import"
        certificate_type: "HTTPS"
        certificate_path: "/path/to/cert.pem"
        ssl_key: "/path/to/private_key.pem"
      delegate_to: localhost

    - name: Export a SSL certificate.
      dellemc.openmanage.idrac_certificates:
        idrac_ip: "{{ idrac_ip }}"
        idrac_user: "{{ idrac_user }}"
        idrac_password: "{{ idrac_password }}"
        ca_path: "/path/to/ca_cert.pem"
        command: "export"
        certificate_type: "HTTPS"
        certificate_path: "/home/omam/mycert_dir"
      delegate_to: localhost

    - name: Import a CSC certificate.
      dellemc.openmanage.idrac_certificates:
        idrac_ip: "{{ idrac_ip }}"
        idrac_user: "{{ idrac_user }}"
        idrac_password: "{{ idrac_password }}"
        ca_path: "/path/to/ca_cert.pem"
        command: "import"
        certificate_type: "CSC"
        certificate_path: "/path/to/cert.pem"
      delegate_to: localhost

    - name: Import a custom certificate with a passphrase.
      dellemc.openmanage.idrac_certificates:
        idrac_ip: "{{ idrac_ip }}"
        idrac_user: "{{ idrac_user }}"
        idrac_password: "{{ idrac_password }}"
        command: "import"
        certificate_type: "CUSTOMCERTIFICATE"
        certificate_path: "/path/to/idrac_cert.p12"
        passphrase: "cert_passphrase"
        reset: false
      delegate_to: localhost

    - name: Export a Client trust certificate.
      dellemc.openmanage.idrac_certificates:
        idrac_ip: "{{ idrac_ip }}"
        idrac_user: "{{ idrac_user }}"
        idrac_password: "{{ idrac_password }}"
        ca_path: "/path/to/ca_cert.pem"
        command: "export"
        certificate_type: "CLIENT_TRUST_CERTIFICATE"
        certificate_path: "/home/omam/mycert_dir"
      delegate_to: localhost
