diff --git a/lib/ansible/plugins/action/debug.py b/lib/ansible/plugins/action/debug.py index 7728d45cc2..08d973eaac 100644 --- a/lib/ansible/plugins/action/debug.py +++ b/lib/ansible/plugins/action/debug.py @@ -54,7 +54,11 @@ class ActionModule(ActionBase): try: results = self._templar.template(self._task.args['var'], convert_bare=True, fail_on_undefined=True, bare_deprecated=False) 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: results = "VARIABLE IS NOT DEFINED!" diff --git a/test/integration/roles/test_var_blending/tasks/main.yml b/test/integration/roles/test_var_blending/tasks/main.yml index 606d80764c..fb2808964d 100644 --- a/test/integration/roles/test_var_blending/tasks/main.yml +++ b/test/integration/roles/test_var_blending/tasks/main.yml @@ -34,3 +34,15 @@ that: - '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' diff --git a/test/integration/roles/test_var_blending/vars/more_vars.yml b/test/integration/roles/test_var_blending/vars/more_vars.yml index bd9592b561..bac93d3e53 100644 --- a/test/integration/roles/test_var_blending/vars/more_vars.yml +++ b/test/integration/roles/test_var_blending/vars/more_vars.yml @@ -1 +1,3 @@ badwolf: badwolf + +same_value_as_var_name_var: "same_value_as_var_name_var"