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()