AnsibleUndefinedVariable: ‘ansible.vars.hostvars.HostVarsVars object’ has no attribute ‘my_var’
Having issues to troubleshoot this error and finding the faulty host? Verbose mode won’t help you, neither will looking at your hosts.
One way to go at it, is to run ad-hoc commands, for instance we want to test the variable “ansible_host” which is (or should be) defined in host vars (we use it for templating):
ansible -i inventory all -m debug -a "var=hostvars[inventory_hostname].ansible_host"
Then you could get grep to filter out the matches like so:
ansible -i inventory all -m debug -a "var=hostvars[inventory_hostname].ansible_host" | grep -B1 "NOT DEFINED"