Ansible: How to use variables defined in inventory file (hosts) in my playbook?


As the subject says. I have some host variables defined in my hosts inventory file. How do I access them in my playbook?

Here is an example. Based on all my research I was expecting foo and bar to be part of hostvars. I can put host specific variables in separate var files, but I would love to keep them in my inventory file “attached” to a host. I don’t want to use it in templates.
ansible version: 1.3.2, ansible_distribution_version: 6.4


Doing the following should work:
debug: msg="foo={{foo}}"

The foo variable will be evaluated in the context of the current host. Tested locally with ansible 1.3.4.

Leave a Reply