Well it does work... but for the 'wrong' groups.

Let me explain:
There's another layer of groups in the inventory to define in which 
datacentre a particular host is.
So in a group like dev-group1 we might have 2 machines in datacentre-A and 
other 2 hosts in datacentre-B.
In this case I'm not interested in where a box is. I need to refer to it by 
it's role. (Not the ansible role, but what it does :) )

So that is why I had this arbitrary list of groups read from a variable. 
And that is still what I would need.
I'm thinking to make a play to define those vars and including another one 
so I can use the "with_items" construct.

If someone has come across something like this before, I would love to hear 
about it! 




We have a number of defined groups which we need

On Thursday, 22 May 2014 13:21:28 UTC, Makimoto Marakatti wrote:
>
> 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, [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/69011f00-04b0-4f76-adca-58d73b9d6cb2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to