Ansible Local Log ( Overwrite Issue)

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

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:
    content: |
      {% for i in groups['all'] %}
      {{ i }} {{ hostvars[i].store.stdout }}
      {% endfor %}
    dest: /etc/ansible/usergroups.txt
  run_omce: true