13lh6w
Last Updated: July 27, 2016
·
27.28K
· lwade
B1f9542b4de2bdfaa801402d9c243f5f

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

8 Responses
Add your response

10428
Lamentconfiguration normal

Awesome trick. :)

over 1 year ago ·
12389
40d7a97fab50680b4a8fb3f3c882b101

Nice!

over 1 year ago ·
13743
24ef80339ca19df482961c1571cda607

Great work! I put this in Ansbile Galaxy for easy re-use.
https://galaxy.ansible.com/list#/roles/646

over 1 year ago ·
14245
Avatar normal

sick!

over 1 year ago ·
17648
Steve   bus sac delta normal

So helpful! Ansible is really opaque and this helps crack open its internals. Thanks.

over 1 year ago ·
17999
None

Is anybody having issues with this on 1.8.2. "tojson" works but "tonice_json" seems to be doing some extra interpolation and breaks

over 1 year ago ·
18536
Ee6f763a240b188df3e36feb5e0b1fbc

Keep coming back here, damn useful tip!

over 1 year ago ·
27494
over 1 year ago ·