ansible/ansible — pull request #7278 by Ernest0x (2014-05-05 13:18:16+00:00)
Title: Evaluate item[*]/item.* in list expressions for with_nested lookup

Support the evaluation of "item[*]" or "item.*" subexpressions
in list expressions for loops constructed with with_nested lookup.
This allows to use the values that were in effect at previous
(less deep) loop levels of a nested loop. E.g. an expression can
use item[0], which is evaluated to the value that was in effect at
level 0 (outside/nesting loop) for each possible loop path/branch.

For example, consider the following setup:

At the hosts file:
[somegroup]
host1.example.org
host2.example.org

[anothergroup]
host3.example.org

at the host_vars of host1.example.org:
network_interfaces:
- name: eth0
address: 1.2.3.4
- name: eth1
address: 1.2.4.5

at the hosts vars of host2.example.org:
network_interfaces:
- name: eth0
address: 1.2.3.5
- name: eth1
address: 1.2.4.6

Now, let's say you want from host "host3.example.org" to ping all
the network interfaces for each host in "somegroup". This patch
allows you to do that like this:

hosts: host3.example.org
command: /bin/ping {{ item.1.address }}
with_nested:
- groups["somegroup"]
- hostvars[item[0]].network_interfaces