---
- hosts: ome
  connection: local
  name: Dell OME Application Certificate Signing Request.
  gather_facts: False

  collections:
    - dellemc.openmanage

  tasks:
  - name: generate certificate signing request.
    ome_application_certificate:
      hostname: "{{ hostname }}"
      username: "{{ username }}"
      password: "{{ password }}"
      command: "generate_csr"
      distinguished_name: "hostname.com"
      department_name: "Remote Access Group"
      business_name: "Dell Inc."
      locality: "Round Rock"
      country_state: "Texas"
      country: "US"
      email: "support@dell.com"
    register: result
    tags:
      - generate

  - name: copy CSR data into a file.
    ansible.builtin.copy:
      content: "{{ result.csr_status.CertificateData }}"
      dest: "csr_data.txt"
    tags:
      - csr-data

  - name: upload the certificate.
    ome_application_certificate:
      hostname: "{{ hostname }}"
      username: "{{ username }}"
      password: "{{ password }}"
      command: "upload"
      upload_file: "/path/certificate.cer"
    tags:
      - upload

  - name: "once certificate uploaded, OME cannot be accessed for few seconds, hence wait for 10 seconds."
    wait_for:
      host: "{{ hostname }}"
      port: "{{ port }}"
      delay: 10
    tags:
      - upload
