---
- name: Device Credential Intent
  hosts: dnac_servers
  vars_files:
    - credentials.yml
  gather_facts: false  # This space must be "no". It was set to false due to formatting errors.but the correct value is "no".
  connection: local
  tasks:

    # Project Info Section

    - name: Create Credentials and assign it to a site.
      cisco.dnac.device_credential_intent:
        dnac_host: "{{ dnac_host }}"
        dnac_port: "{{ dnac_port }}"
        dnac_username: "{{ dnac_username }}"
        dnac_password: "{{ dnac_password }}"
        dnac_verify: "{{ dnac_verify }}"
        dnac_debug: "{{ dnac_debug }}"
        dnac_log: true
        state: merged
        config:
          - global_credential_details:
              cli_credential:
                - description: CLI1
                  username: cli1
                  password: '12345'
                  enable_password: '12345'
              snmp_v2c_read:
                - description: SNMPv2c Read1  # use this for deletion
                  read_community: '123456'
              snmp_v2c_write:
                - description: SNMPv2c Write1  # use this for deletion
                  write_community: '123456'
              snmp_v3:
                - auth_password: '12345678'  # At least 8 characters
                  auth_type: SHA  # [SHA, MD5] (SHA is recommended)
                  snmp_mode: AUTHPRIV  # [AUTHPRIV, AUTHNOPRIV, NOAUTHNOPRIV]
                  privacy_password: '12345678'  # At least 8 characters
                  privacy_type: AES128  # [AE128, AE192, AE256]
                  username: snmpV31
                  description: snmpV31
              https_read:
                - description: HTTP Read1
                  username: HTTP_Read1
                  password: '12345'
                  port: 443
              https_write:
                - description: HTTP Write1
                  username: HTTP_Write1
                  password: '12345'
                  port: 443
            assign_credentials_to_site:
              cli_credential:
                id: 2fc5f7d4-cf15-4a4f-99b3-f086e8dd6350
              snmp_v2c_read:
                id: a966a4e5-9d11-4683-8edc-a5ad8fa59ee3
              snmp_v2c_write:
                id: 7cd072a4-2263-4087-b6ec-93b20958e286
              snmp_v3:
                id: c08a1797-84ce-4add-94a3-b419b13621e4
              https_read:
                id: 1009725d-373b-4e7c-a091-300777e2bbe2
              https_write:
                id: f1ab6e3d-01e9-4d87-8271-3ac5fde83980
              site_name:
                - Global/Chennai/Trill
                - Global/Chennai/Tidel

    - name: Delete Credentials
      cisco.dnac.device_credential_intent:
        dnac_host: "{{ dnac_host }}"
        dnac_port: "{{ dnac_port }}"
        dnac_username: "{{ dnac_username }}"
        dnac_password: "{{ dnac_password }}"
        dnac_verify: "{{ dnac_verify }}"
        dnac_debug: "{{ dnac_debug }}"
        dnac_log: true
        state: deleted
        config:
          - global_credential_details:
              cli_credential:
                - description: CLI1
                  username: cli1
              snmp_v2c_read:
                - description: SNMPv2c Read1  # use this for deletion
              snmp_v2c_write:
                - description: SNMPv2c Write1  # use this for deletion
              snmp_v3:
                - description: snmpV31
              https_read:
                - description: HTTP Read1
                  username: HTTP_Read1
              https_write:
                - description: HTTP Write1
                  username: HTTP_Write1
