When debugging ansible I like to do a json dump of EVERYTHING. But I’m not seeing my extra-vars in my dump. Here’s the jinja template to dump all ansible’s internal variables. What can I add to see the extra-vars?
{
"hostvars": {
{% for key in groups["all"] %}
"{{key}}": {{ hostvars[key] |to_nice_json }}
,
{% endfor %}
"localhost": {{hostvars['localhost'] | to_nice_json}}
},
"vars": {{ vars | to_nice_json }}
,
"environment": {{ environment | to_nice_json }}
,
"group_names": {{ group_names | to_nice_json }}
,
"groups": {{ groups | to_nice_json }}
}
Example Playbook:
- hosts: localhost
tasks:
- shell: echo hello {{ xvar }}
register: hello
- include: dump.pb # this is my JSON dump code
If I run this without defining xvar I get an error. The following command succeeds:
ansible-playbook -i hosts_cpci1 tmp.pb --extra-vars "xvar=world"
The JSON dump shows that xvar=world got through but xvar doesn’t show up in either the vars or localhost listing. Abridged JSON output below.
"hostvars": { "localhost": { "hello": {
"cmd": "echo hello world", } } }
"vars": {
"always_run": false,
"ansible_version": { "full": "1.9.2" },
"delegate_to": "127.0.0.1",
"playbook_dir": "/home/ansible/test",
}