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

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

Awesome trick. :)

over 1 year ago ·
12389

Nice!

over 1 year ago ·
13743

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

over 1 year ago ·
14245

sick!

over 1 year ago ·
17648

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

over 1 year ago ·
17999

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

Keep coming back here, damn useful tip!

over 1 year ago ·
27494
over 1 year ago ·
Filed Under