Backup info saved in TXT file is not in readable format, please help

Below is my playbook to backup info from router and save it to a file. But when i open the TXT file in ansible controller, backup info is very difficult to read. Please look at the screenshot in below link: https://drive.google.com/file/d/1QfDUG8j6NKTRhB78RYOSGZrNLRP8TW54/view?usp=sharing

Iam running ansible network automation device in GNS3. Is it because iam opening this file in ansible/linux device that the data is so dis-organized? If i were to open this TXT file in windows PC, will the data be in a readable format or should i change my script to make data more readable?

  • name: show version and other user level commands

    hosts: R1

    gather_facts: false

    connection: local

    tasks:

    • name: run multiple commands on remote nodes

      ios_command:

      commands:

      • show ip arp
      • show version
      • show int status
      • show int description

      register: print_output

    • name: save output to a file copy: content=“{{ print_output.stdout_lines }}” dest=“./output/{{ inventory_hostname }}.txt”

Below is my playbook to backup info from router and save it to a file. But when i open the TXT file in ansible
controller, backup info is very difficult to read. Please look at the screenshot in below
link: https://drive.google.com/file/d/1QfDUG8j6NKTRhB78RYOSGZrNLRP8TW54/view?usp=sharing
<https://drive.google.com/file/d/1QfDUG8j6NKTRhB78RYOSGZrNLRP8TW54/view?usp=sharing&gt;

Iam running ansible network automation device in GNS3. Is it because iam opening this file in ansible/linux device that
the data is so dis-organized? If i were to open this TXT file in windows PC, will the data be in a readable format or
should i change my script to make data more readable?

  *

    name: show version and other user level commands

    hosts: R1

    gather_facts: false

    connection: local

    tasks:

      o

        name: run multiple commands on remote nodes

        ios_command:

        commands:

          + show ip arp
          + show version
          + show int status
          + show int description

        register: print_output

      o

        name: save output to a file copy: content="{{ print_output.stdout_lines }}" dest="./output/{{ inventory_hostname
        }}.txt"

You can either use print_output.stdout (string) or turn print_output.stdout_line (list) into a string:

print_output.stdout_lines | join('\n')

Regards
       Racke

Hi,

I found the solution after a little research
\n is the ASCII symbol for new line. Ansible was catching the raw output the router was sending over the wire to the terminal emulator software, and for some reason it was getting “\n” rather than “\n”. So below config saves output in proper format.

copy: content=“{{ print_output.stdout | replace(‘\n’, ‘\n’) }}” dest=“./output/router1.txt”

Thanks for trying to help me.