1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

converted error on play var initialization into warning with more information

This commit is contained in:
Brian Coca 2015-03-31 23:07:03 -04:00
parent 17e086fe8c
commit 0d1e2e74a1
2 changed files with 10 additions and 7 deletions

View file

@ -119,7 +119,11 @@ class Play(object):
temp_vars = utils.combine_vars(self.vars, self.vars_file_vars) temp_vars = utils.combine_vars(self.vars, self.vars_file_vars)
temp_vars = utils.combine_vars(temp_vars, self.playbook.extra_vars) temp_vars = utils.combine_vars(temp_vars, self.playbook.extra_vars)
try:
ds = template(basedir, ds, temp_vars) ds = template(basedir, ds, temp_vars)
except errors.AnsibleError, e:
utils.warning("non fatal error while trying to template play variables: %s" % (str(e)))
ds['tasks'] = _tasks ds['tasks'] = _tasks
ds['handlers'] = _handlers ds['handlers'] = _handlers

View file

@ -118,7 +118,10 @@ def template(basedir, varname, templatevars, lookup_fatal=True, depth=0, expand_
if isinstance(varname, basestring): if isinstance(varname, basestring):
if '{{' in varname or '{%' in varname: if '{{' in varname or '{%' in varname:
try:
varname = template_from_string(basedir, varname, templatevars, fail_on_undefined) varname = template_from_string(basedir, varname, templatevars, fail_on_undefined)
except errors.AnsibleError, e:
raise errors.AnsibleError("Failed to template %s: %s" % (varname, str(e)))
if (varname.startswith("{") and not varname.startswith("{{")) or varname.startswith("["): if (varname.startswith("{") and not varname.startswith("{{")) or varname.startswith("["):
eval_results = utils.safe_eval(varname, locals=templatevars, include_exceptions=True) eval_results = utils.safe_eval(varname, locals=templatevars, include_exceptions=True)
@ -188,11 +191,7 @@ class _jinja2_vars(object):
if isinstance(var, dict) and varname == "vars" or isinstance(var, HostVars): if isinstance(var, dict) and varname == "vars" or isinstance(var, HostVars):
return var return var
else: else:
try:
return template(self.basedir, var, self.vars, fail_on_undefined=self.fail_on_undefined) return template(self.basedir, var, self.vars, fail_on_undefined=self.fail_on_undefined)
except:
raise KeyError("undefined variable: %s" % varname)
def add_locals(self, locals): def add_locals(self, locals):
''' '''