diff --git a/lib/ansible/utils/template.py b/lib/ansible/utils/template.py index fd3c48af5cc..9180f47326c 100644 --- a/lib/ansible/utils/template.py +++ b/lib/ansible/utils/template.py @@ -532,13 +532,14 @@ def template_from_string(basedir, data, vars, fail_on_undefined=False): return lookup(*args, basedir=basedir, **kwargs) t.globals['lookup'] = my_lookup - - - jvars =_jinja2_vars(basedir, vars, t.globals, fail_on_undefined) new_context = t.new_context(jvars, shared=True) rf = t.root_render_func(new_context) - res = jinja2.utils.concat(rf) + try: + res = jinja2.utils.concat(rf) + except TypeError, te: + if 'StrictUndefined' in str(te): + raise errors.AnsibleUndefinedVariable("unable to look up a name or access an attribute in template string") return res except (jinja2.exceptions.UndefinedError, errors.AnsibleUndefinedVariable): if fail_on_undefined: