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

20 views
Skip to first unread message

Vikram S

unread,
Feb 18, 2021, 2:25:37 AM2/18/21
to Ansible Project

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"

Stefan Hornburg (Racke)

unread,
Feb 18, 2021, 3:01:27 AM2/18/21
to ansible...@googlegroups.com
On 2/18/21 8:25 AM, Vikram S wrote:
> 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>
>
> 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

> --
> You received this message because you are subscribed to the Google Groups "Ansible Project" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to
> ansible-proje...@googlegroups.com <mailto:ansible-proje...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/93187e0f-4430-4ac3-a452-fd419321c1cfn%40googlegroups.com
> <https://groups.google.com/d/msgid/ansible-project/93187e0f-4430-4ac3-a452-fd419321c1cfn%40googlegroups.com?utm_medium=email&utm_source=footer>.


--
Ecommerce and Linux consulting + Perl and web application programming.
Debian and Sympa administration. Provisioning with Ansible.

OpenPGP_signature

Vikram S

unread,
Feb 20, 2021, 9:42:29 AM2/20/21
to Ansible Project
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.
Reply all
Reply to author
Forward
0 new messages