# Playbook output is not saved properly in file, please guide

**URL:** <https://forum.ansible.com/t/playbook-output-is-not-saved-properly-in-file-please-guide/34586>\
**Category:** Ansible Project\
**Tags:** windows\
**Created:** [February 7, 2021, 10:32pm UTC](https://forum.ansible.com/t/playbook-output-is-not-saved-properly-in-file-please-guide/34586 "2021-02-07T22:32:48Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Vikram\_S](https://avatars.discourse-cdn.com/v4/letter/v/90db22/32.png) [@Vikram\_S](https://forum.ansible.com/u/Vikram_S)\
**Post date:** [February 7, 2021, 10:32pm UTC](https://forum.ansible.com/t/playbook-output-is-not-saved-properly-in-file-please-guide/34586/1 "2021-02-07T22:32:48Z")

</div>

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)

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/ansible/original/1X/1882d9a01da5d8996a862359b0913cc568a39b84.svg) [@system](https://forum.ansible.com/u/system)\
**Post date:** [February 8, 2021, 2:29pm UTC](https://forum.ansible.com/t/playbook-output-is-not-saved-properly-in-file-please-guide/34586/2 "2021-02-08T14:29:40Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Vikram\_S](https://avatars.discourse-cdn.com/v4/letter/v/90db22/32.png) [@Vikram\_S](https://forum.ansible.com/u/Vikram_S)\
**Post date:** [February 8, 2021, 5:13pm UTC](https://forum.ansible.com/t/playbook-output-is-not-saved-properly-in-file-please-guide/34586/3 "2021-02-08T17:13:22Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![ahmad\_aljarah](https://avatars.discourse-cdn.com/v4/letter/a/dec6dc/32.png) [@ahmad\_aljarah](https://forum.ansible.com/u/ahmad_aljarah)\
**Post date:** [March 22, 2021, 8:30pm UTC](https://forum.ansible.com/t/playbook-output-is-not-saved-properly-in-file-please-guide/34586/4 "2021-03-22T20:30:32Z")

</div>

i get wrong format below is my script:

---

<div class="post-metadata">

**Author:** ![ffirg](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/ffirg/32/10029_2.png) [@ffirg](https://forum.ansible.com/u/ffirg)\
**Post date:** [March 22, 2021, 9:49pm UTC](https://forum.ansible.com/t/playbook-output-is-not-saved-properly-in-file-please-guide/34586/5 "2021-03-22T21:49:45Z")

</div>

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](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.

---

<div class="post-metadata">

**Author:** ![Vikram\_S](https://avatars.discourse-cdn.com/v4/letter/v/90db22/32.png) [@Vikram\_S](https://forum.ansible.com/u/Vikram_S)\
**Post date:** [March 24, 2021, 2:13am UTC](https://forum.ansible.com/t/playbook-output-is-not-saved-properly-in-file-please-guide/34586/6 "2021-03-24T02:13:35Z")

</div>

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
