ansible/ansible — pull request #4982 by mivok (2013-11-20 23:41:56+00:00)
Title: Allow with_nested to loop through data structures

This change allows nested lists to refer to the current item in an outer list
using item[0] and item[1] and so on inside the with_nested clause. It does
this by performing the expansion variables on each iteration instead of just
once at the beginning, subsituting in the current values of each.

For example:

Variable data:

---
users:
foo:
ssh_keys:
- "key1"
- "key2"
bar:
ssh_keys:
- "key3"
- "key4"

and a task of:

- debug: msg="{{item[0]}} - {{item[1]}}"
with_nested:
- users.keys()
- users[item[0]]['ssh_keys']

Will give:

ok: [default] => (item=['foo', 'key1']) => {"item": ["foo", "key1"], "msg":
"foo - key1"}
ok: [default] => (item=['foo', 'key2']) => {"item": ["foo", "key2"], "msg":
"foo - key2"}
ok: [default] => (item=['bar', 'key3']) => {"item": ["bar", "key3"], "msg":
"bar - key3"}
ok: [default] => (item=['bar', 'key4']) => {"item": ["bar", "key4"], "msg":
"bar - key4"}