mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-04-24 11:21:25 -07:00
A playbook that does `timezone name=Australia/Brisbane` on a host previously in UTC will appear to take 10 hours. Improve the seconds handling for playbooks that take longer than one hour. Improve the hours handling for playbooks that take longer than one day. TZ change before: ``` Playbook run took 0 days, 10 hours, 0 minutes, 36055 seconds ``` After: ``` Playbook run took 0 days, 0 hours, 0 minutes, 55 seconds ``` Sleep for 100s more than one hour before: ``` Playbook run took 0 days, 1 hours, 1 minutes, 3641 seconds ``` After: ``` Playbook run took 0 days, 1 hours, 1 minutes, 41 seconds ```
36 lines
1.1 KiB
Python
36 lines
1.1 KiB
Python
# Make coding more python3-ish
|
|
from __future__ import (absolute_import, division, print_function)
|
|
__metaclass__ = type
|
|
|
|
from datetime import datetime
|
|
|
|
from ansible.plugins.callback import CallbackBase
|
|
|
|
|
|
class CallbackModule(CallbackBase):
|
|
"""
|
|
This callback module tells you how long your plays ran for.
|
|
"""
|
|
CALLBACK_VERSION = 2.0
|
|
CALLBACK_TYPE = 'aggregate'
|
|
CALLBACK_NAME = 'timer'
|
|
CALLBACK_NEEDS_WHITELIST = True
|
|
|
|
def __init__(self):
|
|
|
|
super(CallbackModule, self).__init__()
|
|
|
|
self.start_time = datetime.utcnow()
|
|
|
|
def days_hours_minutes_seconds(self, runtime):
|
|
minutes = (runtime.seconds // 60) % 60
|
|
r_seconds = runtime.seconds % 60
|
|
return runtime.days, runtime.seconds // 3600, minutes, r_seconds
|
|
|
|
def playbook_on_stats(self, stats):
|
|
self.v2_playbook_on_stats(stats)
|
|
|
|
def v2_playbook_on_stats(self, stats):
|
|
end_time = datetime.utcnow()
|
|
runtime = end_time - self.start_time
|
|
self._display.display("Playbook run took %s days, %s hours, %s minutes, %s seconds" % (self.days_hours_minutes_seconds(runtime)))
|