---
- name: Dell OpenManage Ansible discovery operations.
  hosts: ome
  gather_facts: false

  tasks:
    - name: Discover servers in a range
      dellemc.openmanage.ome_discovery:
        hostname: "{{ hostname }}"
        username: "{{ username }}"
        password: "{{ password }}"
        ca_path: "/path/to/ca_cert.pem"
        discovery_job_name: "Discovery_server_1"
        discovery_config_targets:
          - network_address_detail:
              - 192.96.24.1-192.96.24.255
            device_types:
              - SERVER
            wsman:
              username: user
              password: password
      tags:
        - server_discovery
      delegate_to: localhost

    - name: Discover chassis in a range
      dellemc.openmanage.ome_discovery:
        hostname: "{{ hostname }}"
        username: "{{ username }}"
        password: "{{ password }}"
        ca_path: "/path/to/ca_cert.pem"
        discovery_job_name: "Discovery_chassis_1"
        discovery_config_targets:
          - network_address_detail:
              - 192.96.24.1-192.96.24.255
            device_types:
              - CHASSIS
            wsman:
              username: user
              password: password
      tags:
        - chassis_discovery
      delegate_to: localhost

    - name: Discover switches in a range
      dellemc.openmanage.ome_discovery:
        hostname: "{{ hostname }}"
        username: "{{ username }}"
        password: "{{ password }}"
        ca_path: "/path/to/ca_cert.pem"
        discovery_job_name: "Discover_switch_1"
        discovery_config_targets:
          - network_address_detail:
              - 192.96.24.1-192.96.24.255
            device_types:
              - NETWORK SWITCH
            snmp:
              community: snmp_creds
      tags:
        - switch_discovery
      delegate_to: localhost

    - name: Discover storage in a range
      dellemc.openmanage.ome_discovery:
        hostname: "{{ hostname }}"
        username: "{{ username }}"
        password: "{{ password }}"
        ca_path: "/path/to/ca_cert.pem"
        discovery_job_name: "Discover_storage_1"
        discovery_config_targets:
          - network_address_detail:
              - 192.96.24.1-192.96.24.255
            device_types:
              - STORAGE
            storage:
              username: user
              password: password
            snmp:
              community: community_str
      tags:
        - storage_discovery
      delegate_to: localhost

    - name: Delete a discovery job
      dellemc.openmanage.ome_discovery:
        hostname: "{{ hostname }}"
        username: "{{ username }}"
        password: "{{ password }}"
        ca_path: "/path/to/ca_cert.pem"
        state: "absent"
        discovery_job_name: "Discovery-123"
      tags:
        - delete_discovery
      delegate_to: localhost

    - name: Schedule the discovery of multiple devices ignoring partial failure and enable trap to receive alerts
      dellemc.openmanage.ome_discovery:
        hostname: "{{ hostname }}"
        username: "{{ username }}"
        password: "{{ password }}"
        ca_path: "/path/to/ca_cert.pem"
        state: "present"
        discovery_job_name: "Discovery-123"
        discovery_config_targets:
          - network_address_detail:
              - 192.96.24.1-192.96.24.255
              - 192.96.0.0/24
              - 192.96.26.108
            device_types:
              - SERVER
              - CHASSIS
              - STORAGE
              - NETWORK SWITCH
            wsman:
              username: wsman_user
              password: wsman_pwd
            redfish:
              username: redfish_user
              password: redfish_pwd
            snmp:
              community: snmp_community
          - network_address_detail:
              - 192.96.25.1-192.96.25.255
              - ipmihost
              - esxiserver
              - sshserver
            device_types:
              - SERVER
            ssh:
              username: ssh_user
              password: ssh_pwd
            vmware:
              username: vm_user
              password: vmware_pwd
            ipmi:
              username: ipmi_user
              password: ipmi_pwd
        schedule: RunLater
        cron: "0 0 9 ? * MON,WED,FRI *"
        ignore_partial_failure: true
        trap_destination: true
        community_string: true
        email_recipient: test_email@company.com
      tags:
        - schedule_discovery
      delegate_to: localhost

    - name: Discover servers with ca check enabled
      dellemc.openmanage.ome_discovery:
        hostname: "{{ hostname }}"
        username: "{{ username }}"
        password: "{{ password }}"
        ca_path: "/path/to/ca_cert.pem"
        discovery_job_name: "Discovery_server_ca1"
        discovery_config_targets:
          - network_address_detail:
              - 192.96.24.108
            device_types:
              - SERVER
            wsman:
              username: user
              password: password
              ca_check: true
              certificate_data: "{{ lookup('ansible.builtin.file', '/path/to/certificate_data_file') }}"
      tags:
        - server_ca_check
      delegate_to: localhost

    - name: Discover chassis with ca check enabled data
      dellemc.openmanage.ome_discovery:
        hostname: "192.168.0.1"
        username: "username"
        password: "password"
        ca_path: "/path/to/ca_cert.pem"
        discovery_job_name: "Discovery_chassis_ca1"
        discovery_config_targets:
          - network_address_detail:
              - 192.96.24.108
            device_types:
              - CHASSIS
            redfish:
              username: user
              password: password
              ca_check: true
              certificate_data: "  -----BEGIN CERTIFICATE-----
                ABCDEFGHIJKLMNOPQRSTUVWXYZaqwertyuiopasdfghjklzxcvbnmasdasagasvv
                ABCDEFGHIJKLMNOPQRSTUVWXYZaqwertyuiopasdfghjklzxcvbnmasdasagasvv
                ABCDEFGHIJKLMNOPQRSTUVWXYZaqwertyuiopasdfghjklzxcvbnmasdasagasvv
                aqwertyuiopasdfghjklzxcvbnmasdasagasvv=
                -----END CERTIFICATE----- "
      tags:
        - chassis_ca_check_data
      delegate_to: localhost
