How Do You Troubleshoot the Ansible Error “this task includes an undefined variable”?

Problem scenario
You are running an Ansible playbook, but you get the error "this task includes an undefined variable."  Every variable seems to be defined.  What is wrong?

Possible solution #1
Do one of the variables rely on an index of server names?  If the playbook orchestrates something that responds to Ansible values on other servers and one server is not reachable, you could get this error.  In the "Gathering Facts" stage, was each server connected to?  If one server was temporarily down, an indexing of server names and facts thereof may have not happened.  Thus you could have received an error about an undefined variable.

Possible solution #2
Use the "gather_facts: no" stanza under the module throwing the problem.  Variables derived from facts can be unnecessary.  Configuring the playbook to not gather facts is a workaround.  But this option reduces the number of potential problems that can keep the playbook from running.

Leave a comment

Your email address will not be published. Required fields are marked *