Catch template syntax errors specifically when templating strings

Fixes #9333
pull/9387/head
James Cammarata 10 years ago
parent b0069a338e
commit b61a78532c

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

@ -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,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,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,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) ansible-playbook good_parsing.yml -i $(INVENTORY) -e @$(VARS_FILE) $(CREDENTIALS_ARG) -v $(TEST_FLAGS)
includes: includes:

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

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

Loading…
Cancel
Save