# save stdout to file on localhost.

**URL:** <https://forum.ansible.com/t/save-stdout-to-file-on-localhost/32550>\
**Category:** Ansible Project\
**Created:** [March 27, 2020, 4:10pm UTC](https://forum.ansible.com/t/save-stdout-to-file-on-localhost/32550 "2020-03-27T16:10:32Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mario\_Garcia](https://avatars.discourse-cdn.com/v4/letter/m/b782af/32.png) [@Mario\_Garcia](https://forum.ansible.com/u/Mario_Garcia)\
**Post date:** [March 27, 2020, 4:10pm UTC](https://forum.ansible.com/t/save-stdout-to-file-on-localhost/32550/1 "2020-03-27T16:10:32Z")

</div>

i want to query all the users on the hosts of my inventory and create afile for each hosts with all the privileges for each user

I know that htere tools like freeipa but we do not have those in place

so i am using the getent wrapper to get all the users on the hosts included the netgroups… run sudo -lU on each of these hosts and save the output to file by using stdout or stdout\_lines.

the problems is only one username is saved to the file and not all of them

this is the playbook:

`

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [March 27, 2020, 6:00pm UTC](https://forum.ansible.com/t/save-stdout-to-file-on-localhost/32550/2 "2020-03-27T18:00:20Z")

</div>

This should work:

&nbsp;&nbsp;- name: save to file  
&nbsp;&nbsp;&nbsp;&nbsp;copy:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;content: "{{ sudo\_rights.results | map(attribute='stdout') | join('\n') }}"  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dest: privs\_{{inventory\_hostnam}}  
&nbsp;&nbsp;&nbsp;&nbsp;delegate\_to: localhost

You can't use run once, since you need the task to run one time for each host.
