Ansible Workbook
April 27, 2024
Debug all variables with Ansible
When working with Ansible, one of the “recipes” that I always keep handy is related to debugging variables. I find it particularly useful to have a comprehensive view of the variables associated with a host, defined at the “facts”, environment, group, and host levels.
By setting gather_facts: true
, we can access the variables through:
- Module:
vars
- Environment:
environment
- Group names:
group_names
- Groups:
groups
- Hosts:
hostvars
To print the variables in a readable format, the to_nice_json
filter can be used.