mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
When var name is the same as var content, try to template it before reporting that var is not defined. (#13629)
* When var name is the same as var content, try to template it before reporting that var is not defined. Add asserts in test_var_blending to check this special corner case. * Fix integration tests when using debug with list or dict.
This commit is contained in:
parent
f39ad1f13a
commit
3901556b35
3 changed files with 19 additions and 1 deletions
|
@ -54,7 +54,11 @@ class ActionModule(ActionBase):
|
||||||
try:
|
try:
|
||||||
results = self._templar.template(self._task.args['var'], convert_bare=True, fail_on_undefined=True, bare_deprecated=False)
|
results = self._templar.template(self._task.args['var'], convert_bare=True, fail_on_undefined=True, bare_deprecated=False)
|
||||||
if results == self._task.args['var']:
|
if results == self._task.args['var']:
|
||||||
raise AnsibleUndefinedVariable
|
# if results is not str/unicode type, raise an exception
|
||||||
|
if type(results) not in [str, unicode]:
|
||||||
|
raise AnsibleUndefinedVariable
|
||||||
|
# If var name is same as result, try to template it
|
||||||
|
results = self._templar.template("{{" + results + "}}", convert_bare=True, fail_on_undefined=True)
|
||||||
except AnsibleUndefinedVariable:
|
except AnsibleUndefinedVariable:
|
||||||
results = "VARIABLE IS NOT DEFINED!"
|
results = "VARIABLE IS NOT DEFINED!"
|
||||||
|
|
||||||
|
|
|
@ -34,3 +34,15 @@
|
||||||
that:
|
that:
|
||||||
- 'diff_result.stdout == ""'
|
- 'diff_result.stdout == ""'
|
||||||
|
|
||||||
|
- name: check debug variable with same name as var content
|
||||||
|
debug: var=same_value_as_var_name_var
|
||||||
|
register: same_value_as_var_name
|
||||||
|
|
||||||
|
- name: check debug variable output when variable is undefined
|
||||||
|
debug: var=undefined_variable
|
||||||
|
register: var_undefined
|
||||||
|
|
||||||
|
- assert:
|
||||||
|
that:
|
||||||
|
- var_undefined.undefined_variable == 'VARIABLE IS NOT DEFINED!'
|
||||||
|
- same_value_as_var_name.same_value_as_var_name_var == 'same_value_as_var_name_var'
|
||||||
|
|
|
@ -1 +1,3 @@
|
||||||
badwolf: badwolf
|
badwolf: badwolf
|
||||||
|
|
||||||
|
same_value_as_var_name_var: "same_value_as_var_name_var"
|
||||||
|
|
Loading…
Reference in a new issue