Allow undefined var errors to bubble up when templating vars_files in certain conditions

Follow up to 8769f03c, which allows the undefined var error to be raised
if we're getting vars with a full context (play/host/task) and the host
has already gathered facts. In this way, vars_files containing variables
that fail to be templated are not silently ignored.
This commit is contained in:
James Cammarata 2015-09-21 11:55:07 -04:00
parent f96255f7fd
commit cb7060c9fe

View file

@ -45,6 +45,13 @@ from ansible.vars.unsafe_proxy import UnsafeProxy
CACHED_VARS = dict()
try:
from __main__ import display
display = display
except ImportError:
from ansible.utils.display import Display
display = Display()
def preprocess_vars(a):
'''
Ensures that vars contained in the parameter passed in are
@ -239,7 +246,13 @@ class VariableManager:
else:
raise AnsibleError("vars file %s was not found" % vars_file_item)
except (UndefinedError, AnsibleUndefinedVariable):
continue
if host is not None and self._fact_cache.get(host.name, dict()).get('module_setup') and task is not None:
raise
else:
# we do not have a full context here, and the missing variable could be
# because of that, so just show a warning and continue
display.vvv("skipping vars_file '%s' due to an undefined variable" % vars_file_item)
continue
if not C.DEFAULT_PRIVATE_ROLE_VARS:
for role in play.get_roles():