From ebda14ba41e8d7dc136a255aba5712b4b8ae1c6c Mon Sep 17 00:00:00 2001 From: "patchback[bot]" <45432694+patchback[bot]@users.noreply.github.com> Date: Mon, 15 Nov 2021 22:13:12 +0100 Subject: [PATCH] Enable counter_enabled.py to support batch mode (#3709) (#3731) * Enable counter_enabled.py to support serial mode Enable counter_enabled.py to support batch playbook executions using the serial tag in plays. Currently, the host counter gets reset at the beginning of every task. However, during batch executions we want it to keep track of the previous batch executions and print the host counter based on the previous runs. This proposal keeps track of how many servers have been updated in previous batches and starts the host counter at that tracked value. ``` - hosts: allthethings gather_facts: no serial: - 3 - 15% - 20% - 35% - 55% - 90% - 100% tasks: - name: Ping Hello! ping: data: "Hello!!!!" ``` * Reset task counter on play start Reset task counter on play start for batch mode playbook executions. * Add changelog fragment * change changelog fragment after feedback Co-authored-by: Felix Fontein Co-authored-by: Felix Fontein (cherry picked from commit f5b4dcc564364ccec62016e30c9e88011d2d6290) Co-authored-by: Nabheet Sandhu --- changelogs/fragments/3709-support-batch-mode.yml | 2 ++ plugins/callback/counter_enabled.py | 7 ++++++- 2 files changed, 8 insertions(+), 1 deletion(-) create mode 100644 changelogs/fragments/3709-support-batch-mode.yml diff --git a/changelogs/fragments/3709-support-batch-mode.yml b/changelogs/fragments/3709-support-batch-mode.yml new file mode 100644 index 0000000000..f03e8de6b5 --- /dev/null +++ b/changelogs/fragments/3709-support-batch-mode.yml @@ -0,0 +1,2 @@ +bugfixes: + - counter_enabled callback plugin - fix output to correctly display host and task counters in serial mode (https://github.com/ansible-collections/community.general/pull/3709). diff --git a/plugins/callback/counter_enabled.py b/plugins/callback/counter_enabled.py index 3b6e5e7ad4..38d71df69e 100644 --- a/plugins/callback/counter_enabled.py +++ b/plugins/callback/counter_enabled.py @@ -45,6 +45,8 @@ class CallbackModule(CallbackBase): _task_total = 0 _host_counter = 1 _host_total = 0 + _current_batch_total = 0 + _previous_batch_total = 0 def __init__(self): super(CallbackModule, self).__init__() @@ -76,8 +78,11 @@ class CallbackModule(CallbackBase): self._display.banner(msg) self._play = play + self._previous_batch_total = self._current_batch_total + self._current_batch_total = self._previous_batch_total + len(self._all_vars()['vars']['ansible_play_batch']) self._host_total = len(self._all_vars()['vars']['ansible_play_hosts_all']) self._task_total = len(self._play.get_tasks()[0]) + self._task_counter = 1 def v2_playbook_on_stats(self, stats): self._display.banner("PLAY RECAP") @@ -145,7 +150,7 @@ class CallbackModule(CallbackBase): path = task.get_path() if path: self._display.display("task path: %s" % path, color=C.COLOR_DEBUG) - self._host_counter = 0 + self._host_counter = self._previous_batch_total self._task_counter += 1 def v2_runner_on_ok(self, result):