mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Catch recursive templating errors and display what string caused them.
This commit is contained in:
parent
2b58145599
commit
4cd69e81b9
1 changed files with 9 additions and 1 deletions
|
@ -414,7 +414,15 @@ def template_from_string(basedir, data, vars):
|
|||
# TODO: may need some way of using lookup plugins here seeing we aren't calling
|
||||
# the legacy engine, lookup() as a function, perhaps?
|
||||
environment.template_class = J2Template
|
||||
t = environment.from_string(data)
|
||||
|
||||
try:
|
||||
t = environment.from_string(data)
|
||||
except RuntimeError, re:
|
||||
if 'recursion' in str(re):
|
||||
raise errors.AnsibleError("recursive loop detected in template string: %s" % data)
|
||||
else:
|
||||
raise ree
|
||||
|
||||
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:
|
||||
|
|
Loading…
Reference in a new issue