Catch template syntax errors specifically when templating strings

Fixes #9333
This commit is contained in:
James Cammarata 2014-10-20 13:10:42 -05:00
parent b0069a338e
commit b61a78532c
4 changed files with 7 additions and 2 deletions

View file

@ -340,6 +340,8 @@ def template_from_string(basedir, data, vars, fail_on_undefined=False):
try:
t = environment.from_string(data)
except TemplateSyntaxError, e:
raise errors.AnsibleError("template error while templating string: %s" % str(e))
except Exception, e:
if 'recursion' in str(e):
raise errors.AnsibleError("recursive loop detected in template string: %s" % data)

View file

@ -26,6 +26,7 @@ parsing:
ansible-playbook bad_parsing.yml -i $(INVENTORY) -e @$(VARS_FILE) $(CREDENTIALS_ARG) -vvv $(TEST_FLAGS) --tags common,scenario2; [ $$? -eq 3 ]
ansible-playbook bad_parsing.yml -i $(INVENTORY) -e @$(VARS_FILE) $(CREDENTIALS_ARG) -vvv $(TEST_FLAGS) --tags common,scenario3; [ $$? -eq 3 ]
ansible-playbook bad_parsing.yml -i $(INVENTORY) -e @$(VARS_FILE) $(CREDENTIALS_ARG) -vvv $(TEST_FLAGS) --tags common,scenario4; [ $$? -eq 3 ]
ansible-playbook bad_parsing.yml -i $(INVENTORY) -e @$(VARS_FILE) $(CREDENTIALS_ARG) -vvv $(TEST_FLAGS) --tags common,scenario5; [ $$? -eq 3 ]
ansible-playbook good_parsing.yml -i $(INVENTORY) -e @$(VARS_FILE) $(CREDENTIALS_ARG) -v $(TEST_FLAGS)
includes:

View file

@ -49,5 +49,7 @@
failed_when: False
tags: scenario4
- name: test that a missing/malformed jinja2 filter fails
debug: msg="{{output_dir|badfiltername}}"
tags: scenario5

View file

@ -92,7 +92,7 @@
- name: set a fact to check that we ran this play
set_fact: genus_LAMA=true
- hosts: '{{genus'
- hosts: 'genus'
gather_facts: false
tasks:
- name: no hosts should match this group