mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Enable counter_enabled.py to support batch mode (#3709)
* 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 <felix@fontein.de> Co-authored-by: Felix Fontein <felix@fontein.de>
This commit is contained in:
parent
115d435d2d
commit
f5b4dcc564
2 changed files with 8 additions and 1 deletions
2
changelogs/fragments/3709-support-batch-mode.yml
Normal file
2
changelogs/fragments/3709-support-batch-mode.yml
Normal file
|
@ -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).
|
|
@ -45,6 +45,8 @@ class CallbackModule(CallbackBase):
|
||||||
_task_total = 0
|
_task_total = 0
|
||||||
_host_counter = 1
|
_host_counter = 1
|
||||||
_host_total = 0
|
_host_total = 0
|
||||||
|
_current_batch_total = 0
|
||||||
|
_previous_batch_total = 0
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
super(CallbackModule, self).__init__()
|
super(CallbackModule, self).__init__()
|
||||||
|
@ -76,8 +78,11 @@ class CallbackModule(CallbackBase):
|
||||||
self._display.banner(msg)
|
self._display.banner(msg)
|
||||||
self._play = play
|
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._host_total = len(self._all_vars()['vars']['ansible_play_hosts_all'])
|
||||||
self._task_total = len(self._play.get_tasks()[0])
|
self._task_total = len(self._play.get_tasks()[0])
|
||||||
|
self._task_counter = 1
|
||||||
|
|
||||||
def v2_playbook_on_stats(self, stats):
|
def v2_playbook_on_stats(self, stats):
|
||||||
self._display.banner("PLAY RECAP")
|
self._display.banner("PLAY RECAP")
|
||||||
|
@ -145,7 +150,7 @@ class CallbackModule(CallbackBase):
|
||||||
path = task.get_path()
|
path = task.get_path()
|
||||||
if path:
|
if path:
|
||||||
self._display.display("task path: %s" % path, color=C.COLOR_DEBUG)
|
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
|
self._task_counter += 1
|
||||||
|
|
||||||
def v2_runner_on_ok(self, result):
|
def v2_runner_on_ok(self, result):
|
||||||
|
|
Loading…
Reference in a new issue