Viewing ansible variables

When developing ansible playbooks and roles it’s extremely useful to be able to see all of the variables available to you. This is super easy with the ansible setup and debug modules:

# List all of the vars available to the host
$ ansible haproxy01.* -m setup

# Retrieve all of the groups from the inventory file
$ ansible haproxy01.* -m debug -a "var=groups"

Lester Wade took this a step further and wrote a great blog entry that describes how to dump the contents of the vars, environment, group_names, hostvars and group variables to a file. If you run his example you will get a nicely formatted text file in /tmp/ansible.all

Module Variables ("vars"):
--------------------------------
{
    "ansible_all_ipv4_addresses": [
        "192.168.1.122",
        "192.168.1.124"
    ],
    "ansible_all_ipv6_addresses": [
        "fe80::250:56ff:fe8f:b8ad"
    ],
    "ansible_apparmor": {
        "status": "disabled"
    },

This file is a great reference and kudos to Lester for the amazing work!

Leave a Reply

Your email address will not be published. Required fields are marked *