From d149ea52228744f9885564da970d9f8339de36d5 Mon Sep 17 00:00:00 2001 From: Brian Coca Date: Mon, 29 Jun 2015 13:26:30 -0400 Subject: [PATCH] ported timer.py callback to v2 --- lib/ansible/plugins/callback/timer.py | 35 +++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 lib/ansible/plugins/callback/timer.py diff --git a/lib/ansible/plugins/callback/timer.py b/lib/ansible/plugins/callback/timer.py new file mode 100644 index 00000000000..4b28a19af09 --- /dev/null +++ b/lib/ansible/plugins/callback/timer.py @@ -0,0 +1,35 @@ +import os +import datetime +from datetime import datetime, timedelta + +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' + + start_time = datetime.now() + + def __init__(self, display): + + super(CallbackModule, self).__init__(display) + + start_time = datetime.now() + self._display.warning("Timerv2 plugin is active from included callbacks.") + + def days_hours_minutes_seconds(self, timedelta): + minutes = (timedelta.seconds//60)%60 + r_seconds = timedelta.seconds - (minutes * 60) + return timedelta.days, timedelta.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.now() + timedelta = end_time - self.start_time + self._display.display("Playbook run took %s days, %s hours, %s minutes, %s seconds" % (self.days_hours_minutes_seconds(timedelta))) +