I run a playbook with a single command against multiple Cisco Nexus hosts. For all hosts, I want to store the output of the commands in a single file on the controller.
---
- name: Nxos
hosts:
- sw1
- sw2
gather_facts: false
tasks:
- name: interface counters
cisco.nxos.nxos_command:
commands: show interface counters errors non-zero
register: output
However, with this method below, only 1 host's output is saved and not the others.
- name: copy output to file
copy: content="{{ output.stdout[0] }}" dest="output.txt"
Whereas, if I use the below method, sometimes the output is stored for all hosts while other times it only stores output for a random number of hosts
- name: Copy output to file
local_action:
module: lineinfile
path: output.txt
line: "###{{ inventory_hostname }}### \n\n {{ output.stdout[0] }}"
create: yes
Any idea what could be wrong or what the best way to store the output be?
Thanks