Fix list index out of range

If the failure occurs on the first task, ansible throws a warning about
the call back because it's attempting to set the end time for the
previous task which does not exist.

Change-Id: Ied1d9cbbfdf61c622a99205bc8a8ea9f2f5e57a5
This commit is contained in:
Alex Schultz 2020-12-18 08:35:53 -07:00
parent ba5db95b09
commit 32e4898cf0
1 changed files with 2 additions and 1 deletions

View File

@ -179,7 +179,8 @@ class CallbackModule(CallbackBase):
end_time = current_time()
time_elapsed = secondsToStr(time.time() - self.t0)
for result in self.results:
result['tasks'][-1]['task']['duration']['end'] = end_time
if len(result['tasks']) > 1:
result['tasks'][-1]['task']['duration']['end'] = end_time
result['play']['duration']['end'] = end_time
result['play']['duration']['time_elapsed'] = time_elapsed