At 2014-05-22 05:21:35 -0700, [email protected] 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 [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/20140522130459.GD17698%40toroid.org.
For more options, visit https://groups.google.com/d/optout.

Reply via email to