# Complete debug output to file

**URL:** <https://forum.ansible.com/t/complete-debug-output-to-file/35057>\
**Category:** Ansible Project\
**Created:** [April 26, 2021, 1:03pm UTC](https://forum.ansible.com/t/complete-debug-output-to-file/35057 "2021-04-26T13:03:19Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dimitri\_Yioulos1](https://avatars.discourse-cdn.com/v4/letter/d/9dc877/32.png) [@Dimitri\_Yioulos1](https://forum.ansible.com/u/Dimitri_Yioulos1)\
**Post date:** [April 26, 2021, 1:03pm UTC](https://forum.ansible.com/t/complete-debug-output-to-file/35057/1 "2021-04-26T13:03:19Z")

</div>

Hello, all.

It’s been a long time since I posted here, so please forgive any posting faux pas.

I’ve created the following playboos:

---

<div class="post-metadata">

**Author:** ![racke](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/racke/32/4767_2.png) [@racke](https://forum.ansible.com/u/racke)\
**Post date:** [April 26, 2021, 2:34pm UTC](https://forum.ansible.com/t/complete-debug-output-to-file/35057/2 "2021-04-26T14:34:39Z")

</div>

> Hello, all.
> 
> It's been a long time since I posted here, so please forgive any posting faux pas.
> 
> I've created the following playboos:
> 
> ---  
> - name: report aws migrator  
> hosts: all  
> gather\_facts: false  
> tasks:  
> - name: collect facts  
> shell:  
> cmd: facter -p fqdn processorcount memorysize\_mb blockdevice\_sda\_size blockdevice\_vda\_size operatingsystem  
> operatingsystemrelease is\_virtual processor0 --json  
> register: facter\_output
> 
> ```
> \- name: print output
> debug:
> msg: &quot;\{\{ facter\_output\.stdout \}\}&quot;
> \- local\_action: copy content=&quot;\{\{ facter\_output\.stdout \}\}&quot;\. dest=&quot;/Users/dyioulos/Documents/prodrept\.txt&quot;
> 
> ```
> 
> The problem is with the output to file. Data are overwritten, and

information for only the last host the playbook is

> run against is captured. Additionally, i have to put any character here (denoted by ^): - local\_action: copy  
> content="{{ facter\_output.stdout }}"^ dest="/Users/dyioulos/Documents/prodrept.txt" in order for the output to be in  
> json format. That extra character is also printed, including if I

use newline) is also printed.

> Your help in soving this would be greatly appreciated.

Hello Dimitri,

to collect the output from all hosts please try the following approach:

- local\_action:  
&nbsp;&nbsp;&nbsp;&nbsp;module: copy  
&nbsp;&nbsp;&nbsp;&nbsp;content: |  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{% for host in ansible\_play\_hosts %}  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{{ host }}  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{{ hostvars[host]['facter\_output']['stdout'] }}

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{% endfor %}  
&nbsp;&nbsp;&nbsp;&nbsp;dest: "/Users/dyioulos/Documents/prodrept.txt"  
&nbsp;&nbsp;run\_once: yes

Regards  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Racke

---

<div class="post-metadata">

**Author:** ![Dimitri\_Yioulos1](https://avatars.discourse-cdn.com/v4/letter/d/9dc877/32.png) [@Dimitri\_Yioulos1](https://forum.ansible.com/u/Dimitri_Yioulos1)\
**Post date:** [April 26, 2021, 3:08pm UTC](https://forum.ansible.com/t/complete-debug-output-to-file/35057/3 "2021-04-26T15:08:26Z")

</div>

That worked great; thank you so much!

---

<div class="post-metadata">

**Author:** ![Dimitri\_Yioulos1](https://avatars.discourse-cdn.com/v4/letter/d/9dc877/32.png) [@Dimitri\_Yioulos1](https://forum.ansible.com/u/Dimitri_Yioulos1)\
**Post date:** [April 26, 2021, 3:28pm UTC](https://forum.ansible.com/t/complete-debug-output-to-file/35057/4 "2021-04-26T15:28:49Z")

</div>

Racke,

For my edification, might I ask exactly what your code does?

Thanks,

Dimitri

---

<div class="post-metadata">

**Author:** ![Dimitri\_Yioulos1](https://avatars.discourse-cdn.com/v4/letter/d/9dc877/32.png) [@Dimitri\_Yioulos1](https://forum.ansible.com/u/Dimitri_Yioulos1)\
**Post date:** [April 30, 2021, 12:44pm UTC](https://forum.ansible.com/t/complete-debug-output-to-file/35057/5 "2021-04-30T12:44:16Z")

</div>

I’m not sure if I should create another post for this ask: forgive me if I should. As per Racke, here’s my playbook now, and it works great:
