Provide more information in AnsibleUndefinedVariable (#71666)

* Provide more information in AnsibleUndefinedVariable

Fixes #55152
pull/71863/head
Martin Krizek 4 years ago committed by GitHub
parent 6984081111
commit 00b22ab55e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -0,0 +1,2 @@
bugfixes:
- Provide more information in AnsibleUndefinedVariable (https://github.com/ansible/ansible/issues/55152)

@ -104,8 +104,8 @@ class AnsibleJ2Vars(Mapping):
value = None
try:
value = self._templar.template(variable)
except AnsibleUndefinedVariable:
raise
except AnsibleUndefinedVariable as e:
raise AnsibleUndefinedVariable("%s: %s" % (to_native(variable), e.message))
except Exception as e:
msg = getattr(e, 'message', None) or to_native(e)
raise AnsibleError("An unhandled exception occurred while templating '%s'. "

@ -22,3 +22,6 @@ ansible-playbook filter_plugins.yml -v "$@"
# https://github.com/ansible/ansible/issues/68699
ansible-playbook unused_vars_include.yml -v "$@"
# https://github.com/ansible/ansible/issues/55152
ansible-playbook undefined_var_info.yml -v "$@"

@ -0,0 +1,15 @@
- hosts: localhost
gather_facts: no
vars:
foo: []
bar: "{{ foo[0] }}"
tasks:
- debug:
msg: "{{ bar }}"
register: result
ignore_errors: yes
- assert:
that:
- '"foo[0]" in result.msg'
- '"object has no element 0" in result.msg'
Loading…
Cancel
Save