Ansible variables come from a variety of sources. It is for example possible to provide host_vars and group_vars by creating YAML files in a subfolder named host_vars
and group_vars
respectively of the folder containing the inventory file.
How can I list all of the variables Ansible would know about a group or host inside a playbook? Note: I tried ansible -m debug -e 'var=hostvars' host
and ansible -m debug -e '- debug: var=hostvars'
to no avail.
Hint: ansible <group|host> -m setup
is not the correct answer as it does not include all the variables that come from other sources (it only contains { "ansible_facts" : { ... } }
. In fact it does not even include variables provided by a dynamic inventory script (via _meta
and so on).
Ansible version: 1.9.1.
2.0.2
, this doesn't seem to work anymore. The output islocalhost | SUCCESS => { "hostvars": "<ansible.vars.hostvars.HostVars object at 0x7f320943da10>" }
– Zulakis Feb 25 '16 at 10:34"var=hostvars[inventory_hostname]"
on ansible > 2.0 – stuart-warren Mar 09 '16 at 13:37ansible my.hostname.example.com -m setup -i ../my/inventory/hosts.example -u root
– akostadinov Mar 11 '16 at 15:07ansible host-name -m debug -a "var=[var_name]" -i inventory/testing/hosts
– Montaro Sep 18 '17 at 12:09