Skip to content

Instantly share code, notes, and snippets.

@gnosek
Created August 2, 2013 12:12
Show Gist options
  • Save gnosek/6139435 to your computer and use it in GitHub Desktop.
Save gnosek/6139435 to your computer and use it in GitHub Desktop.
Cannot return a dict from custom facts
---
- hosts: $host
tasks:
- environment:
- debug: msg="{{ env_HOME }}"
- debug: msg="{{ environment.HOME }}"
- debug: msg="{{ environment }}"
#!/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
})
$ 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