---
- name: Device Credential Workflow Manager
  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:
    - name: Create global device credentials.
      cisco.dnac.device_credential_workflow_manager:
        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_verify: true
        config:
          - global_credential_details:
              cli_credential:
                - description: CLI1
                  username: cli1
                  password: '12345'
                  enable_password: '12345'
                  # old_description:
                  # old_username:
              snmp_v2c_read:
                - description: SNMPv2c Read1  # use this for deletion
                  read_community: '123456'
                  # old_description:  # use this for updating the description
              snmp_v2c_write:
                - description: SNMPv2c Write1  # use this for deletion
                  write_community: '123456'
                  # old_description: # use this for updating the description
              snmp_v3:
                - auth_password: '12345678'  # Atleast 8 characters
                  auth_type: SHA  # [SHA, MD5] (SHA is recommended)
                  snmp_mode: AUTHPRIV  # [AUTHPRIV, AUTHNOPRIV, NOAUTHNOPRIV]
                  privacy_password: '12345678'  # Atleast 8 characters
                  privacy_type: AES128  # [AE128, AE192, AE256]
                  username: snmpV31
                  description: snmpV31
                  # old_description:
              https_read:
                - description: HTTP Read1
                  username: HTTP_Read1
                  password: '12345'
                  port: 443
                  # old_description:
                  # old_username:
              https_write:
                - description: HTTP Write1
                  username: HTTP_Write1
                  password: '12345'
                  port: 443
                  # old_description:
                  # old_username:

    - name: Assign global device credentials to a site.
      cisco.dnac.device_credential_workflow_manager:
        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_verify: true
        config:
          - assign_credentials_to_site:
              cli_credential:
                description: CLI
                username: cli
              snmp_v2c_read:
                description: SNMPv2c Read
              snmp_v2c_write:
                description: SNMPv2c Write
              snmp_v3:
                description: snmpV3
              https_read:
                description: HTTP Read
                username: HTTP_Read
              https_write:
                description: HTTP Write
                username: HTTP_Write
              site_name:
                - Global/Chennai/Trill
                - Global/Chennai/Tidel

    - name: Delete credentials
      cisco.dnac.device_credential_workflow_manager:
        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_verify: true
        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
