Playbook output is not saved properly in file, please guide

I am practising writing ansible playbook using Network automation docker container in GNS3. After running below playbook, only the output of first command is saved (show version) and i don’t see the 2nd command’s output in file. This happens for any command i run.

Am i doing something wrong or should i export the .txt file to a windows PC to view the complete output?

(formatting below is not in proper order while pasting here but playbook has the correct format)

This will only print the first element of 'stdout', remove the [0] to
get the full thing.

print_output.stdout[0]

vs

print_output.stdout

Yes, removing [0] worked!!
I am learning ansible using a udemy tutorial and i am practising sample playbook in tutorial in GNS3. I am not sure why it worked for the author to save output of multiple commands with [0] present. It’s a 3 yr old course, probably something changed in ansible recently.

i get wrong format below is my script:

you might want to use stdout_lines but it would be better to use the https://github.com/ansible-collections/cisco.iosxr/blob/main/docs/cisco.iosxr.iosxr_config_module.rst#ciscoiosxriosxr_config module with the backup parameter, as this should do the job for you.

Hi,

Use the below syntax and that will fix the issue.

  • name: SAVE BACKUP TO A FILE NAMED WITH DEVICE HOSTNAME
    copy: content=“{{ print_backup.stdout | join (‘\n’) }}" dest=”./iosupgrade/{{ inventory_hostname }}.txt"

Regards,
Vikram