---
- name: Command Runner Run Command
  hosts: dnac_servers
  vars_files:
    - credentials.yml
  gather_facts: false
  tasks:
    - name: Run command
      cisco.dnac.command_runner_run_command:
        dnac_host: "{{ dnac_host }}"
        dnac_username: "{{ dnac_username }}"
        dnac_password: "{{ dnac_password }}"
        dnac_verify: "{{ dnac_verify }}"
        commands:
          - pwd
        deviceUuids:
          - a9b86e42-6573-4f5d-a0bf-a743e290f46a
      register: result

    - name: Show result
      ansible.builtin.debug:
        msg: "{{ result }}"

    - name: Get task info
      cisco.dnac.task_info:
        dnac_host: "{{ dnac_host }}"
        dnac_username: "{{ dnac_username }}"
        dnac_password: "{{ dnac_password }}"
        dnac_verify: "{{ dnac_verify }}"
        taskId: "{{ result.dnac_response.response.taskId }}"
      when:
        - result.dnac_response is defined
        - result.dnac_response.response is defined
        - result.dnac_response.response.taskId is defined
      register: task_result

    - name: Show retrieved task
      ansible.builtin.debug:
        msg: "{{ task_result.dnac_response.response }}"
      when:
        - task_result is defined
        - task_result.dnac_response is defined
