diff --git a/lib/ansible/plugins/action/debug.py b/lib/ansible/plugins/action/debug.py index 2280b65615..06337e564c 100644 --- a/lib/ansible/plugins/action/debug.py +++ b/lib/ansible/plugins/action/debug.py @@ -43,10 +43,8 @@ class ActionModule(ActionBase): result = super(ActionModule, self).run(tmp, task_vars) - verbosity = 0 # get task verbosity - if 'verbosity' in self._task.args: - verbosity = int(self._task.args['verbosity']) + verbosity = int(self._task.args.get('verbosity', 0)) if verbosity <= self._display.verbosity: if 'msg' in self._task.args: @@ -61,8 +59,10 @@ class ActionModule(ActionBase): 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!" + except AnsibleUndefinedVariable as e: + results = u"VARIABLE IS NOT DEFINED!" + if self._display.verbosity > 0: + results += u": %s" % to_text(e) if isinstance(self._task.args['var'], (list, dict)): # If var is a list or dict, use the type as key to display diff --git a/test/integration/targets/var_blending/roles/test_var_blending/tasks/main.yml b/test/integration/targets/var_blending/roles/test_var_blending/tasks/main.yml index e18c480a75..33c66d9b9f 100644 --- a/test/integration/targets/var_blending/roles/test_var_blending/tasks/main.yml +++ b/test/integration/targets/var_blending/roles/test_var_blending/tasks/main.yml @@ -44,7 +44,7 @@ - assert: that: - - var_undefined.undefined_variable == 'VARIABLE IS NOT DEFINED!' + - "'VARIABLE IS NOT DEFINED!' in var_undefined.undefined_variable" - same_value_as_var_name.same_value_as_var_name_var == 'same_value_as_var_name_var' - name: cleanup temporary template output