# How To:  Query servers, write output to file

**URL:** <https://forum.ansible.com/t/how-to-query-servers-write-output-to-file/25642>\
**Category:** Ansible Project\
**Created:** [September 29, 2017, 7:37pm UTC](https://forum.ansible.com/t/how-to-query-servers-write-output-to-file/25642 "2017-09-29T19:37:39Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![John\_Harmon](https://avatars.discourse-cdn.com/v4/letter/j/edb3f5/32.png) [@John\_Harmon](https://forum.ansible.com/u/John_Harmon)\
**Post date:** [September 29, 2017, 7:37pm UTC](https://forum.ansible.com/t/how-to-query-servers-write-output-to-file/25642/1 "2017-09-29T19:37:39Z")

</div>

I know I can script this, but I am wondering if there is a way via ansible to basically grab the contents of a file on a remote server, format it, and write it to a local file? For example, I want to gather all users/groups listed in the sudoers file, and format it as such:

DATE:   
ServerA  
root   
userA

ServerB  
 …

ServerC  
root   
userA   
%GroupA

I am not concerned about the regexp needed, mostly I am wanting to grab data, format it as above, and append contents to a file

---

<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:** [September 29, 2017, 7:39pm UTC](https://forum.ansible.com/t/how-to-query-servers-write-output-to-file/25642/2 "2017-09-29T19:39:22Z")

</div>

fetch/slurp to grab the file

local\_action: temlate ... and do the format generation in the jinaj2 template.

---

<div class="post-metadata">

**Author:** ![John\_Harmon](https://avatars.discourse-cdn.com/v4/letter/j/edb3f5/32.png) [@John\_Harmon](https://forum.ansible.com/u/John_Harmon)\
**Post date:** [September 29, 2017, 8:25pm UTC](https://forum.ansible.com/t/how-to-query-servers-write-output-to-file/25642/3 "2017-09-29T20:25:51Z")

</div>

Thank you
