Thanks for the insightful answer. I'm definitely going to try this and will 
write here how it goes

On Thursday, 22 May 2014 13:04:59 UTC, ams wrote:
>
> At 2014-05-22 05:21:35 -0700, maki...@gmail.com <javascript:> wrote: 
> > 
> > So I made an attempt to loop over each group: 
>
> I'm sorry, my earlier answer was short-sighted. I started thinking about 
> loops because your Subject said "loop", but you were right to not use an 
> Ansible loop in the first placeā€”at least not over groups/hosts. 
>
> As I understand it, trying to write a single task that loops over groups 
> and hosts isn't the way to do things in Ansible. One should write a task 
> that fetches the desired files, and run it against the desired hosts by 
> using the existing host-selection mechanism, as described in 
> http://docs.ansible.com/intro_patterns.html 
>
> So you could do something like: 
>
>     - name: fetch files from the server 
>       fetch: src={{ item }} 
>         dest=/backup/{{ group_names[0] }}/{{ inventory_hostname }}/{{ item 
> | basename }} 
>       with_items: 
>         - /root/.bash_profile 
>         - /some/other/file 
>
> Note that group_names is a list variable that contains the name of all 
> groups that the current host is in. If your hosts aren't in multiple 
> groups, this should not matter to you. If they are, then the backups 
> will be stored only in the directory of the first group by this task. 
>
> Hope this helps. 
>
> -- ams 
>

-- 
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 ansible-project+unsubscr...@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/20f1e71e-dd1b-416d-8215-e77ea669fabf%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to