Ansible debug variables
How to use the Ansible debug module to inspect all available variables, including environment, group names, groups, and host variables.
The following Ansible task prints out all available variable categories in a single debug output. This is helpful when troubleshooting playbooks or exploring what data is available at runtime. It collects module variables, environment variables, group names, groups, and host variables and formats them as JSON.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
- name: xyz
vars:
msg: |
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 }}
debug:
msg: "{{ msg.split('\n') }}"
tags: debug_info
This post is licensed under CC BY 4.0 by the author.