AnsibleUndefinedVariable: ‘ansible.vars.hostvars.HostVarsVars object’ has no attribute ‘my_var’

Pedro Gomes
Dec 5, 2021

--

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"

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

No responses yet

Write a response