Last Updated: April 07, 2019
·
62.42K
· 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

Awesome trick. :)

over 1 year ago ·

Nice!

over 1 year ago ·

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

over 1 year ago ·

sick!

over 1 year ago ·

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

over 1 year ago ·

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 ·

Keep coming back here, damn useful tip!

over 1 year ago ·
over 1 year ago ·