Ansible multiple commands to a file You can see bellow how it looks like my Ansible Script.
My question is what i need to change to get output from multiple commands to a file.The problem is that i get output only from the first command.
I have 200 vrf,do i really need to make multiple tasks fior multiple commands,or there is another solution for it.
I would highly appreciate any response.
---
- name: PING_TenGig_Ethernet_VRFs
  hosts: fr1.s05
  gather_facts: false
  connection: local

  tasks:
    - name: run multiple commands on remote nodes
      ios_command:
        commands:
          - show bgp vrf Mgmt-intf
          - show bgp vrf cha-00 all summary
          - show bgp vrf cha-001 all summary
          - show bgp vrf cha-002 all summary
          - show bgp vrf cha-00303 all summary

      register: print_output

    -  debug: var=print_output.stdout_lines

    - name: save output to a file
      copy: content=&quot;{{ print_output.stdout[0] }}&quot; dest=&quot;./output/{{ inventory_hostname }}.txt&quot;
Judging by the documentation, the result of your run multiple commands on remote nodes block is an array. You're writing only the first item of that array with {{ print_output.stdout[0] }}. The [0] here is the pointer to the first element of the array. Try removing it and see if the result fits your needs.
UPD: Use this to write several strings into a file:
- name: save output to a file
  lineinfile:
    create: yes
    line: &quot;{{item}}&quot;
    path: ./output/{{ inventory_hostname }}.txt
  with_items: &quot;{{ print_output.stdout }}&quot;