* Provide more information in AnsibleUndefinedVariable
Fixes #55152
(cherry picked from commit 00b22ab55e
)
This commit is contained in:
parent
c4e3552c8d
commit
4df129c6ae
4 changed files with 22 additions and 2 deletions
|
@ -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
|
value = None
|
||||||
try:
|
try:
|
||||||
value = self._templar.template(variable)
|
value = self._templar.template(variable)
|
||||||
except AnsibleUndefinedVariable:
|
except AnsibleUndefinedVariable as e:
|
||||||
raise
|
raise AnsibleUndefinedVariable("%s: %s" % (to_native(variable), e.message))
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
msg = getattr(e, 'message', None) or to_native(e)
|
msg = getattr(e, 'message', None) or to_native(e)
|
||||||
raise AnsibleError("An unhandled exception occurred while templating '%s'. "
|
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
|
# https://github.com/ansible/ansible/issues/68699
|
||||||
ansible-playbook unused_vars_include.yml -v "$@"
|
ansible-playbook unused_vars_include.yml -v "$@"
|
||||||
|
|
||||||
|
# https://github.com/ansible/ansible/issues/55152
|
||||||
|
ansible-playbook undefined_var_info.yml -v "$@"
|
||||||
|
|
15
test/integration/targets/template/undefined_var_info.yml
Normal file
15
test/integration/targets/template/undefined_var_info.yml
Normal file
|
@ -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…
Reference in a new issue