From 5c171c1b950c4abd48ca5960ab3d24188942df59 Mon Sep 17 00:00:00 2001 From: AlanCoding Date: Wed, 8 Jan 2020 09:50:03 -0500 Subject: [PATCH] Sanitize debug var= tasks of the loop variable --- changelogs/fragments/66269-hide-debug-loop-vars.yml | 2 ++ lib/ansible/plugins/callback/__init__.py | 5 +++++ 2 files changed, 7 insertions(+) create mode 100644 changelogs/fragments/66269-hide-debug-loop-vars.yml diff --git a/changelogs/fragments/66269-hide-debug-loop-vars.yml b/changelogs/fragments/66269-hide-debug-loop-vars.yml new file mode 100644 index 00000000000..0044865ac81 --- /dev/null +++ b/changelogs/fragments/66269-hide-debug-loop-vars.yml @@ -0,0 +1,2 @@ +bugfixes: + - "Fixed it so that debug tasks using var option will no longer show loop control variables." diff --git a/lib/ansible/plugins/callback/__init__.py b/lib/ansible/plugins/callback/__init__.py index 229728aa225..5de97ad5c0f 100644 --- a/lib/ansible/plugins/callback/__init__.py +++ b/lib/ansible/plugins/callback/__init__.py @@ -269,6 +269,11 @@ class CallbackBase(AnsiblePlugin): # 'var' value as field, so eliminate others and what is left should be varname for hidme in self._hide_in_debug: result.pop(hidme, None) + # when using loop control, remove these vars in addition to the var they reference + for control_var in ('ansible_loop_var', 'ansible_index_var'): + if control_var in result: + loop_var = result.pop(control_var) + result.pop(loop_var, None) def _print_task_path(self, task, color=C.COLOR_DEBUG): path = task.get_path()