ansible/ansible — pull request #8019 by sergevanginderachter (2014-07-02 18:55:33+00:00)
Title: allow set_facts action plugin to work with loops

This patch combines the different set facts in the result set into
a fact holding a list of the original facts.

This allows to create more complex lists, from simple data, to
save a result list to be used in different tasks, without having to
repeat patterns of {{ item.... }} or to combine or nest different
lookup plugins to create a list.

This is by far also a better solution than #4627

Example:
------------

Given this test playbook:
```
---
- hosts: localhost
gather_facts: false
vars:
users:
- name: paul
uid: 1
hosts:
- host: apple
- host: berry
- name: pete
uid: 2
hosts:
- host: banana
- host: pear
- host: kiwi
tasks:
- set_fact:
args:
userslist:
name: '{{ item.0.name }}'
uid: '{{ item.0.uid }}'
host: '{{ item.1.host }}'
with_subelements:
- users
- hosts
```
The original result for the set fact would be
```
"userslist": {
"host": "kiwi",
"name": "pete",
"uid": "2"
}
```
With this patch, one gets:
```
"userslist": [
{
"host": "apple",
"name": "paul",
"uid": "1"
},
{
"host": "berry",
"name": "paul",
"uid": "1"
},
{
"host": "banana",
"name": "pete",
"uid": "2"
},
{
"host": "pear",
"name": "pete",
"uid": "2"
},
{
"host": "kiwi",
"name": "pete",
"uid": "2"
}
]

```