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.
pull/12457/head
James Cammarata 9 years ago
parent f96255f7fd
commit cb7060c9fe

@ -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,6 +246,12 @@ class VariableManager:
else:
raise AnsibleError("vars file %s was not found" % vars_file_item)
except (UndefinedError, AnsibleUndefinedVariable):
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:

Loading…
Cancel
Save