Dump all variables
For debugging purposes it can be useful to not just dump hostvars but also all other variables and group information. You can do this using a jinja template which you could include in a debug task, like so:
tasks:
- name: Dump all vars
action: template src=templates/dumpall.j2 dest=/tmp/ansible.all
Then in dumpall.j2:
Module Variables ("vars"):
--------------------------------
{{ vars | to_nice_json }}
Environment Variables ("environment"):
--------------------------------
{{ environment | to_nice_json }}
GROUP NAMES Variables ("group_names"):
--------------------------------
{{ group_names | to_nice_json }}
GROUPS Variables ("groups"):
--------------------------------
{{ groups | to_nice_json }}
HOST Variables ("hostvars"):
--------------------------------
{{ hostvars | to_nice_json }}
The capability to dump vars and environment vars was enabled by this commit: https://github.com/robparrott/ansible/commit/81e2d871aa9a9fe8fce757c5b1c139b18db361f2
Written by Lester Wade
Related protips
8 Responses
Awesome trick. :)
Nice!
Great work! I put this in Ansbile Galaxy for easy re-use.
https://galaxy.ansible.com/list#/roles/646
sick!
So helpful! Ansible is really opaque and this helps crack open its internals. Thanks.
Is anybody having issues with this on 1.8.2. "tojson" works but "tonice_json" seems to be doing some extra interpolation and breaks
Keep coming back here, damn useful tip!
Now a module on github! https://github.com/f500/ansible-dumpall