From 4cd69e81b92231c1625bf0e7ff7987629b7d8554 Mon Sep 17 00:00:00 2001 From: Michael DeHaan Date: Sat, 6 Apr 2013 09:55:31 -0400 Subject: [PATCH] Catch recursive templating errors and display what string caused them. --- lib/ansible/utils/template.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/ansible/utils/template.py b/lib/ansible/utils/template.py index b99734eaa32..91a915648d7 100644 --- a/lib/ansible/utils/template.py +++ b/lib/ansible/utils/template.py @@ -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: