Created
August 2, 2013 12:12
-
-
Save gnosek/6139435 to your computer and use it in GitHub Desktop.
Cannot return a dict from custom facts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
- hosts: $host | |
tasks: | |
- environment: | |
- debug: msg="{{ env_HOME }}" | |
- debug: msg="{{ environment.HOME }}" | |
- debug: msg="{{ environment }}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# this is actually library/environment | |
import os | |
import json | |
env = { 'env_{0}'.format(k): v for k, v in os.environ.items() } | |
facts = { | |
'environment': dict(os.environ), | |
} | |
facts.update(env) | |
print json.dumps({ | |
'ansible_facts': facts | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ ansible-playbook -i ../hosts -e host=monitor environment.yml | |
PLAY [monitor] **************************************************************** | |
GATHERING FACTS *************************************************************** | |
ok: [monitor] | |
TASK: [environment ] ********************************************************** | |
ok: [monitor] | |
TASK: [debug msg="{{env_HOME}}"] ********************************************** | |
ok: [monitor] => {"msg": "/root"} | |
TASK: [debug msg="{{environment.HOME}}"] ************************************** | |
ok: [monitor] => {"msg": "{{environment.HOME}}"} | |
TASK: [debug msg="{{environment}}"] ******************************************* | |
ok: [monitor] => {"msg": "{}"} | |
PLAY RECAP ******************************************************************** | |
monitor : ok=5 changed=0 unreachable=0 failed=0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment