diff --git a/lib/ansible/plugins/callback/json.py b/lib/ansible/plugins/callback/json.py index c04dd49e237..3961a78aab9 100644 --- a/lib/ansible/plugins/callback/json.py +++ b/lib/ansible/plugins/callback/json.py @@ -29,6 +29,7 @@ DOCUMENTATION = ''' type: bool ''' +import datetime import json from functools import partial @@ -38,6 +39,10 @@ from ansible.inventory.host import Host from ansible.plugins.callback import CallbackBase +def current_time(): + return '%sZ' % datetime.datetime.utcnow().isoformat() + + class CallbackModule(CallbackBase): CALLBACK_VERSION = 2.0 CALLBACK_TYPE = 'stdout' @@ -51,7 +56,10 @@ class CallbackModule(CallbackBase): return { 'play': { 'name': play.get_name(), - 'id': str(play._uuid) + 'id': str(play._uuid), + 'duration': { + 'start': current_time() + } }, 'tasks': [] } @@ -60,7 +68,10 @@ class CallbackModule(CallbackBase): return { 'task': { 'name': task.get_name(), - 'id': str(task._uuid) + 'id': str(task._uuid), + 'duration': { + 'start': current_time() + } }, 'hosts': {} } @@ -110,6 +121,9 @@ class CallbackModule(CallbackBase): task_result.update(on_info) task_result['action'] = task.action self.results[-1]['tasks'][-1]['hosts'][host.name] = task_result + end_time = current_time() + self.results[-1]['tasks'][-1]['task']['duration']['end'] = end_time + self.results[-1]['play']['duration']['end'] = end_time def __getattribute__(self, name): """Return ``_record_task_result`` partial with a dict containing skipped/failed if necessary"""