@@ -32,6 +32,8 @@ def formatted_print(message):
3232 print ("```" )
3333 print ("\n " )
3434
35+ def print_job_output ():
36+
3537ansible_instance = AAPServer (ansibletower , username , password , apiToken )
3638request = ansible_instance .create_request ()
3739headers = ansible_instance .create_header (request )
@@ -46,23 +48,25 @@ def formatted_print(message):
4648api_url = '/api/v2/%s/%s/' % (status_path_component , job_id )
4749
4850response = request .get (api_url , contentType = 'application/json' ,headers = headers )
51+ num_tries += 1
4952if response .isSuccessful ():
5053 result = json .loads (response .response )
5154 status = result ['status' ]
52- print status
53- task .setStatusLine ("Job id %s %s" % (job_id , status ))
55+ task .setStatusLine ("Job id %s %s" % (job_id , status ))
56+ formatted_print (">>> Task status after " + str (num_tries ) + " tries is " + status )
57+ print (link_message % (str (job_id ), ansibletower ['url' ], str (job_id )))
58+ print ("\n " )
5459 if status in ["running" ,"pending" ,"waiting" ]:
55- num_tries += 1
5660 if max_retries :
5761 if num_tries > max_retries :
62+ job_output = request .get (api_url + 'stdout/' , contentType = 'text/plain' ,headers = headers ).response
63+ formatted_print (job_output )
5864 raise Exception ("Error: maximum number of tries reached" )
5965 task .schedule ("ansibletower/launchAndWait.wait_for_completion.py" , int (wait_interval ))
6066else :
67+ formatted_print (">>> Task failed after " + str (num_tries ) + " tries." )
6168 raise Exception ("Failed: Server return [%s], with content [%s]" % (response .status , response .response ))
6269
63- formatted_print (">>> Task completed after " + str (num_tries ) + " tries with status " + status )
6470job_output = request .get (api_url + 'stdout/' , contentType = 'text/plain' ,headers = headers ).response
6571formatted_print (job_output )
66- print (link_message % (str (job_id ), ansibletower ['url' ], str (job_id )))
67- print ("\n " )
6872result = job_output
0 commit comments