From d9713759070b2cc3db2c3bf453086409399b52f4 Mon Sep 17 00:00:00 2001 From: sean-m-sullivan Date: Fri, 28 Aug 2020 07:35:13 -0500 Subject: [PATCH] updated to error if finished not in result --- .../plugins/module_utils/tower_api.py | 22 +++++++++++-------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/awx_collection/plugins/module_utils/tower_api.py b/awx_collection/plugins/module_utils/tower_api.py index dfab8ad9ab..28a4355574 100644 --- a/awx_collection/plugins/module_utils/tower_api.py +++ b/awx_collection/plugins/module_utils/tower_api.py @@ -594,17 +594,21 @@ class TowerAPIModule(TowerModule): # Grab our start time to compare against for the timeout start = time.time() result = self.get_endpoint(url) - while not result['json']['finished']: - # If we are past our time out fail with a message - if timeout and timeout < time.time() - start: - self.json_output['msg'] = 'Monitoring of {0} "{1}" aborted due to timeout'.format(object_type, object_name) - self.fail_json(**self.json_output) + if result['json']['finished'] is None: + self.json_output['msg'] = 'Monitoring of {0} "{1}" aborted due to timeout'.format(object_type, object_name) + self.fail_json(**self.json_output) + else: + while not result['json']['finished']: + # If we are past our time out fail with a message + if timeout and timeout < time.time() - start: + self.json_output['msg'] = 'Monitoring of {0} "{1}" aborted due to timeout'.format(object_type, object_name) + self.fail_json(**self.json_output) - # Put the process to sleep for our interval - time.sleep(interval) + # Put the process to sleep for our interval + time.sleep(interval) - result = self.get_endpoint(url) - self.json_output['status'] = result['json']['status'] + result = self.get_endpoint(url) + self.json_output['status'] = result['json']['status'] # If the job has failed, we want to raise a task failure for that so we get a non-zero response. if result['json']['failed']: