Debugging Ansible - where is it looking at?

Hi all,

I’m having trouble putting variables in the right places. I don’t believe the documentation actually states where Ansible will look for the variables and i have hit and miss some.
Currently using ansible 1.9.2 on CentOS 7.
Tree structure is as follows:
ansible.cfg
hosts
group_vars/
all
host_vars/
hostname1
playbooks/
play1.yml
roles/
role1/
tasks/
main.yml
templates/
template1.j2

when i run ansible-playbook playbooks/play1.yml which creates a file from template1.j2, it is giving me an error saying variable is undefined. The variable is defined in host_vars/hostname1 and the hosts file only has hostname1 in it. However if I were to define the same variable in group_vars/all, it works.

I’m wondering if there’s a way to see which file or folder ansible is reading to look for a particular variable.

I previously found out that the group_vars will required to be on the same directory as the hosts file (or whatever you configure the inventory file is). I would assume that the host_vars/ will require to sit on the same level.

Thanks.

seems like i forgot to ask the questions, silly me (it was written quite late after a long day at work).

Question 1: Is it possible to get Ansible to report where it is looking at for a variable? -vvvv switch doesn’t provide any additional information. is there a log i can look at?

Question 2: Do you have an idea why my template isn’t looking at the host_vars/hostname1 for the variable but have no issues if i were to define the same variable in group_vars/all?

Thanks.

Found the answer for Question 2, the mistake was on me with my play pointing the host as localhost.

As for Question 1, it would still be good to have Ansible report back where it is trying to look.

Thanks.

Hi Jason!

No there is currently no simple switch to get a dump of variables with their “source”.