# Ansible Local Log ( Overwrite Issue)

**URL:** <https://forum.ansible.com/t/ansible-local-log-overwrite-issue/30262>\
**Category:** Ansible Project\
**Created:** [May 3, 2019, 2:38pm UTC](https://forum.ansible.com/t/ansible-local-log-overwrite-issue/30262 "2019-05-03T14:38:52Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tiz](https://avatars.discourse-cdn.com/v4/letter/t/f07891/32.png) [@Tiz](https://forum.ansible.com/u/Tiz)\
**Post date:** [May 3, 2019, 2:38pm UTC](https://forum.ansible.com/t/ansible-local-log-overwrite-issue/30262/1 "2019-05-03T14:38:52Z")

</div>

Hey guys, i need to log into a local file the user’s group of a specific user for all the Virtual Machines my Vcenter hosts. Actually my playbook works, but there’s a issue because the data is overwritten on the destination file, so only the information of the last virtual machine results.  
(i’m new to Ansible, can anyone help me?)  
That’s the code i worte:

- hosts: all  
tasks:
- command: groups user  
register: store
- local\_action: “copy content=‘{{inventory\_hostname}} {{ store.stdout }}\n’ dest=/etc/ansible/usergroups.txt”

Thank you

---

<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:** [May 8, 2019, 7:53pm UTC](https://forum.ansible.com/t/ansible-local-log-overwrite-issue/30262/2 "2019-05-08T19:53:58Z")

</div>

All the host is trying to write to the same file at once and only one of them "wins".  
What you need to do is loop over all host with jinja template in one copy task with run\_once.

. copy:  
&nbsp;&nbsp;&nbsp;&nbsp;content: |  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{% for i in groups['all'] %}  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{{ i }} {{ hostvars[i].store.stdout }}  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{% endfor %}  
&nbsp;&nbsp;&nbsp;&nbsp;dest: /etc/ansible/usergroups.txt  
&nbsp;&nbsp;run\_omce: true
