ansible/ansible — pull request #209 by jhoekx (2012-04-23 19:38:30+00:00)
Title: Allow modules to return facts.

If the module result contains "ansible_facts", that will be added to the setup cache.

This fixes #203.

Example module:

```python
#!/usr/bin/env python

import json
import sys

print json.dumps( {"ansible_facts": {"myname":"jeroen"}} )
sys.exit(0)
```

Example playbook:

```
- hosts: all
vars:
- testvar: "ok"
tasks:
- name: ping
action: ping all
- name: custom facts
action: custom
- name: test
action: template src=../templates/root/facts.txt dest=/root/facts.txt
```

Template:
```
Facts:
{{ ansible_kernel }}
{{ hostvars['rh6oranode2']['ansible_eth0']['ipv4']['address'] }}
{{ myname }}
Above {{ testvar }}.
```

Result:
```
[root@rh6oranode1 ~]# cat facts.txt
Facts:
2.6.32-220.el6.x86_64
192.168.122.52
jeroen
Above ok.
```

Facter/Ohai only dummy-tested since I don't have them on my systems.

Also, what's the use of `_add_result_to_setup_cache` in Runner? When run in a subprocess, the global setup cache can't be modified? I probably miss something in my understanding...