template: Raise UndefinedError exception
In template_from_string, raise an undefined error if it occurs. Have the caller catch it and throw an AnsibleUndefinedVariable
This commit is contained in:
parent
c947802805
commit
d4bbf492b0
2 changed files with 18 additions and 12 deletions
|
@ -31,6 +31,7 @@ import sys
|
|||
import shlex
|
||||
import pipes
|
||||
import re
|
||||
import jinja2
|
||||
|
||||
import ansible.constants as C
|
||||
import ansible.inventory
|
||||
|
@ -574,8 +575,12 @@ class Runner(object):
|
|||
tmp = self._make_tmp_path(conn)
|
||||
|
||||
# render module_args and complex_args templates
|
||||
try:
|
||||
module_args = template.template(self.basedir, module_args, inject)
|
||||
complex_args = template.template(self.basedir, complex_args, inject)
|
||||
except jinja2.exceptions.UndefinedError, e:
|
||||
raise errors.AnsibleUndefinedVariable("Undefined variables: %s" % str(e))
|
||||
|
||||
|
||||
result = handler.run(conn, tmp, module_name, module_args, inject, complex_args)
|
||||
|
||||
|
|
|
@ -496,6 +496,7 @@ def template_from_string(basedir, data, vars):
|
|||
res = jinja2.utils.concat(t.root_render_func(t.new_context(_jinja2_vars(basedir, vars, t.globals), shared=True)))
|
||||
return res
|
||||
except jinja2.exceptions.UndefinedError:
|
||||
raise
|
||||
# this shouldn't happen due to undeclared check above
|
||||
return data
|
||||
# return data
|
||||
|
||||
|
|
Loading…
Reference in a new issue