Search code examples
linuxansiblecisco

Ansible Cisco output creating empty file


Only output from the first command is written to the file.

How do I make it write output from all of the commands to the file?

---

- name: run show commands
  hosts: nexus1
  gather_facts: False


  tasks:
  - name: run show commands on nexus
    nxos_command:
      commands:
        - show hostname
        - show ip route
        - show interface
        - show ip interface vrf all 
        - show hsrp
    register: output

  - name: Copy to server
    copy:
      content: "{{ output.stdout[0] }}"
      dest: "/home/CiscoOutPut/{{ inventory_hostname }}.txt"

Solution

  • You're only asking for output from the first command. output.stdout is a list, one item for the output of each command. When ask for output.stdout[0], you're asking for only the first result.

    If you want to write the output of all commands to a file, then something like:

      - name: Copy to server
        copy:
          content: "{{ '\n'.join(output.stdout) }}"
          dest: "/home/CiscoOutPut/{{ inventory_hostname }}.txt"