[Short Tip] Show all variables of a host

Ansible Logo

There are multiple sources where variables for Ansible can be defined. Most of them can be shown via the setup module, but there are more.

For example, if you use a dynamic inventory script to access a Satellite server many variables like the organization are provided via the inventory script – and these are not shown in setup usually.

To get all variables of a host use the following notation:

---
- name: dump all
  hosts: all

  tasks:
  - name: get variables
    debug: var=hostvars[inventory_hostname]

Use this during debug to find out if the variables you’ve set somewhere are actually accessible in your playbooks.

3 thoughts on “[Short Tip] Show all variables of a host”

  1. I didn’t know this method, but I don’t see what is, in fact, the difference with information get from setup module with ansible -i MyInventory -m setup MyHost. I did a test on the same machine, and the only information wich is not in the “setup” method is the group to which the machine belongs.

    1. Thanks for the comment! As mentioned in the blog post, variables from dynamic inventories are not all shown in the setup module – like the group variables. And if you need to access those (or just want to get them to debug your playbooks) the above mentioned way to address them helps.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s