---
- name: Discover devices using multiple discovery specific credentials and delete all the discoveries
  hosts: localhost
  connection: local
  gather_facts: false  # This space must be "no". It was set to false due to formatting errors.but the correct value is "no".

  vars_files:
    - "{{ CLUSTERFILE }}"

  vars:
    dnac_login: &dnac_login
      dnac_host: "{{ dnac_host }}"
      dnac_username: "{{ dnac_username }}"
      dnac_password: "{{ dnac_password }}"
      dnac_verify: "{{ dnac_verify }}"
      dnac_port: "{{ dnac_port }}"
      dnac_version: "{{ dnac_version }}"
      dnac_debug: "{{ dnac_debug }}"
      dnac_log: true
      dnac_log_level: DEBUG

  tasks:

    - name: Execute discovery devices using MULTI RANGE with various global credentials
      cisco.dnac.discovery_workflow_manager:
        <<: *dnac_login
        state: merged
        config_verify: true
        config:
          - discovery_name: Multi_global
            discovery_type: MULTI RANGE
            ip_address_list:
              - 204.1.2.1-204.1.2.5
              - 204.192.3.40
              - 204.192.4.200
              - 204.1.2.6
              - 204.1.2.7
              - 204.1.2.8
              - 204.1.2.9
              - 204.1.2.10
              - 204.1.2.11
            global_credentials:
              cli_credentials_list:
                - description: ISE
                  username: cisco
                - description: CLI1234  # Incorrect name passed
                  username: cli
              http_read_credential_list:
                - description: HTTP Read
                  username: HTTP_Read
              snmp_v3_credential_list:
                - description: snmpV3
                  username: snmpV3
            protocol_order: ssh

    - name: Execute discovery of single device using various discovery specific credentials and all the global credentials
      cisco.dnac.discovery_workflow_manager:
        <<: *dnac_login
        state: merged
        config_verify: true
        config:
          - discovery_name: Single IP Discovery
            discovery_type: "SINGLE"
            ip_address_list:
              - 204.1.2.5
            discovery_specific_credentials:
              cli_credentials_list:
                - username: cisco
                  password: Cisco#123
                  enable_password: Cisco#123
              http_read_credential:
                username: string
                password: Lablab#123
                port: 443
                secure: true
              snmp_v2_read_credential:
                desc: string
                community: string
              snmp_v2_write_credential:
                desc: string
                community: string
              snmp_v3_credential:
                username: v3Public2
                snmp_mode: AUTHPRIV
                auth_type: SHA
                auth_password: Lablab#1234
                privacy_type: AES256
                privacy_password: Lablab#1234
            protocol_order: ssh

    - name: Execute discovery of single device using various discovery specific credentials only
      cisco.dnac.discovery_workflow_manager:
        <<: *dnac_login
        state: merged
        config_verify: true
        config:
          - discovery_name: Single without Global Credentials
            discovery_type: "SINGLE"
            ip_address_list:
              - 204.1.2.5
            use_global_credentials: false
            discovery_specific_credentials:
              cli_credentials_list:
                - username: cisco
                  password: Cisco#123
                  enable_password: Cisco#123
              http_read_credential:
                username: string
                password: Lablab#123
                port: 443
                secure: true
              snmp_v2_read_credential:
                desc: string
                community: string
              snmp_v2_write_credential:
                desc: string
                community: string
              snmp_v3_credential:
                username: v3Public2
                snmp_mode: AUTHPRIV
                auth_type: SHA
                auth_password: Lablab#1234
                privacy_type: AES256
                privacy_password: Lablab#1234
            protocol_order: ssh

    - name: Execute discovery devices using MULTI RANGE with various discovery specific credentials and all global credentials (max 5 allowed)
      cisco.dnac.discovery_workflow_manager:
        <<: *dnac_login
        state: merged
        config_verify: true
        config:
          - discovery_type: "MULTI RANGE"
            discovery_name: Multi_range
            ip_address_list:
              - 204.1.2.1-204.1.2.100  # It will be taken as 204.1.2.1 - 204.1.2.1
              - 205.2.1.1-205.2.1.10
            ip_filter_list:
              - 204.1.2.5  # Devie with IP 204.1.2.5 won't be discovered
            discovery_specific_credentials:
              cli_credentials_list:
                - username: admin
                  password: maglev123
                  enable_password: maglev123
              http_read_credential:
                username: admin
                password: maglev123
                port: 443
                secure: true
              snmp_v2_read_credential:
                desc: new
                community: password
              snmp_v3_credential:
                username: administrator
                snmp_mode: AUTHPRIV
                auth_password: admin123
                auth_type: SHA
                privacy_type: AES192
                privacy_password: cisco#123
            protocol_order: ssh
            start_index: 1
            records_to_return: 1000
            snmp_version: v2

    - name: Execute discovery devices using CDP/LLDP/CIDR leveraging discovery specific credentials and all the global credentials
      cisco.dnac.discovery_workflow_manager:
        <<: *dnac_login
        state: merged
        config_verify: true
        config:
          - discovery_name: CDP_Test_1
            discovery_type: "CDP"  # Can be LLDP and CIDR
            ip_address_list:    # List length should be one
              - 204.1.2.1
            cdp_level: 2  # Instead use lldp_level for LLDP and prefix length for CIDR
            discovery_specific_credentials:
              cli_credentials_list:
                - username: admin
                  password: maglev123
                  enable_password: maglev123
            protocol_order: ssh

    - name: Execute deletion of single discovery from the dashboard
      cisco.dnac.discovery_workflow_manager:
        <<: *dnac_login
        state: deleted
        config_verify: true
        config:
          - discovery_name: CDP_Test_1

    - name: Execute deletion of all the discoveries from the dashboard
      cisco.dnac.discovery_workflow_manager:
        <<: *dnac_login
        state: deleted
        config_verify: true
        config:
          - delete_all: true
