" So, I am considering to teach "with_nested" lookup to understand
expressions with "item[0]" in the second term as expressions that should be
reevaluated to a list for each item in the first term"

Ansible is not meant to be a programming language, when syntax gets so
complicated that it appears to become one, I feel a playbook is strongly
going in the wrong direction.

It is usually useful to step back and think about the underlying use case,
and there's a clean way to model it without trying to "program in YAML"

I find this problem mostly comes from users coming from Chef, but not
always.

So, as such, I feel this is a bit of a slippery slope.  Rather than
initially discussing the patch, let's understand what's the real world
thing you are trying to configure, at a high level, and we can likely offer
up some suggestions.



On Tue, Apr 29, 2014 at 4:09 AM, 'Petros Moisiadis' via Ansible Project <
[email protected]> wrote:

>  On 04/29/2014 02:57 AM, Michael DeHaan wrote:
>
> "In a task, I am trying to figure out how I can loop over the items of a
> list that is defined as a host variable for each host in a specific
> group."
>
>  If the variable is "listvar"
>
>  with_items: listvar
>
>
>
> What you suggest is the simplest form of a loop. It does not handle the
> "for each host in a specific group" part. What I want is that the task must
> run for all the items in each list for each host in a specific group.
> Particularly, I would need a mechanism, so that the outer loop loops over
> hosts and the inner loop uses the host in the current step in the outer
> loop to get the needed host variable.
>
> In general, this is a common case of a nested loop with the inner loop
> using the value of the current step in the outer loop. Unfortunately, it
> seems that Ansible does not support this. The current implementation of
> "with_nested" loop expects its terms to be static lists all evaluated
> before the execution of the loop. It does not support the second list to be
> created dynamically for each step in the outer loop. So, I am considering
> to teach "with_nested" lookup to understand expressions with "item[0]" in
> the second term as expressions that should be reevaluated to a list for
> each item in the first term. For example, the loop I need could be simply
> written like this:
>
> with_nested:
>     - groups["somegroup"]
>     - hostvars[item[0]].listvar
>
> Would you accept a patch for that?
>
>
>
> On Mon, Apr 28, 2014 at 3:37 PM, 'Petros Moisiadis' via Ansible Project <
> [email protected]> wrote:
>
>>  On 04/28/2014 09:56 PM, Adam Morris wrote:
>>
>>
>>
>> On Monday, April 28, 2014 10:35:15 AM UTC-7, Ernest0x wrote:
>>>
>>> In a task, I am trying to figure out how I can loop over the items of a
>>> list that is defined as a host variable for each host in a specific
>>> group.
>>>
>>
>>  I'm not sure what you are trying to do here so I can't offer too much
>> advice.  It also depends on what you are planning on doing with those
>> variables I suspect.
>>
>>
>>  Given the example I wrote in my previous post, what I want is simply to
>> have the task run for each item in  "mylist" for each host in "somegroup".
>> Thus, have the task run for 5 times: for item1, item2, item3, item4 and
>> item5.
>>
>>
>>  You might want to look at this
>> http://docs.ansible.com/playbooks_variables.html#magic-variables-and-how-to-access-information-about-other-hosts
>>
>>  Normally I only need to iterate over a list of variables for the
>> current host.  But there are examples of accessing variables for groups of
>> hosts on that page.
>>
>>
>>  I already know about these 'magic' vars. The difficulty is not on how to
>> get the data, but on how to construct the loop so that I get the iteration
>> I want.
>>
>>
>>  Adam
>>  --
>> 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/26c8f5ac-db7c-4171-8c7c-0f9605a212d4%40googlegroups.com<https://groups.google.com/d/msgid/ansible-project/26c8f5ac-db7c-4171-8c7c-0f9605a212d4%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>>
>>   --
>> 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/535EADE1.40309%40yahoo.gr<https://groups.google.com/d/msgid/ansible-project/535EADE1.40309%40yahoo.gr?utm_medium=email&utm_source=footer>.
>>
>>
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>  --
> 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/CA%2BnsWgwx9Ne97ckJOmvJQb4rgCPQX3agQjC2AuQXdeJQAdwJ%2BQ%40mail.gmail.com<https://groups.google.com/d/msgid/ansible-project/CA%2BnsWgwx9Ne97ckJOmvJQb4rgCPQX3agQjC2AuQXdeJQAdwJ%2BQ%40mail.gmail.com?utm_medium=email&utm_source=footer>
> .
>
> For more options, visit https://groups.google.com/d/optout.
>
>
>  --
> 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/535F5E36.4020200%40yahoo.gr<https://groups.google.com/d/msgid/ansible-project/535F5E36.4020200%40yahoo.gr?utm_medium=email&utm_source=footer>
> .
>
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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/CA%2BnsWgxb6f8UPCD1tFf7wDHN_yCDfLWGOwsLfZ%2BsJ2btTVFjSA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to