On 03.05.2019 16:38, Tiz wrote:
> 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"
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
--
You received this message because you are subscribed to the Google Groups
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/ansible-project/0356b0d3-99e5-e539-4244-277b05e8db80%40olstad.com.
For more options, visit https://groups.google.com/d/optout.