mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Check that AnsibleUndefinedVariable doesn't occur when an unused variable references an undefined variable (#35571)
* Check that AnsibleUndefinedVariable doesn't occur * AnsibleUndefinedVariable exc.: don't modify type
This commit is contained in:
parent
c37b997abc
commit
d608eb9530
3 changed files with 15 additions and 1 deletions
|
@ -23,7 +23,7 @@ from collections import Mapping
|
|||
|
||||
from jinja2.utils import missing
|
||||
|
||||
from ansible.errors import AnsibleError
|
||||
from ansible.errors import AnsibleError, AnsibleUndefinedVariable
|
||||
from ansible.module_utils.six import iteritems
|
||||
from ansible.module_utils._text import to_native
|
||||
|
||||
|
@ -105,6 +105,8 @@ class AnsibleJ2Vars(Mapping):
|
|||
value = None
|
||||
try:
|
||||
value = self._templar.template(variable)
|
||||
except AnsibleUndefinedVariable:
|
||||
raise
|
||||
except Exception as e:
|
||||
msg = getattr(e, 'message') or to_native(e)
|
||||
raise AnsibleError("An unhandled exception occurred while templating '%s'. "
|
||||
|
|
8
test/integration/targets/template/runme.sh
Executable file
8
test/integration/targets/template/runme.sh
Executable file
|
@ -0,0 +1,8 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
set -eux
|
||||
|
||||
ANSIBLE_ROLES_PATH=../ ansible-playbook template.yml -i ../../inventory -e @../../integration_config.yml -v "$@"
|
||||
|
||||
# Test for #35571
|
||||
ansible testhost -i testhost, -m debug -a 'msg={{ hostvars["localhost"] }}' -e "vars1={{ undef }}" -e "vars2={{ vars1 }}"
|
4
test/integration/targets/template/template.yml
Normal file
4
test/integration/targets/template/template.yml
Normal file
|
@ -0,0 +1,4 @@
|
|||
- hosts: testhost
|
||||
gather_facts: yes
|
||||
roles:
|
||||
- { role: template }
|
Loading…
Reference in a new issue