Ansible Local Log ( Overwrite Issue)

16 views
Skip to first unread message

Tiz

unread,
May 3, 2019, 10:38:52 AM5/3/19
to Ansible Project
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

Kai Stian Olstad

unread,
May 8, 2019, 3:54:09 PM5/8/19
to ansible...@googlegroups.com
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


--
Kai Stian Olstad
Reply all
Reply to author
Forward
0 new messages