diff --git a/app/settings.py b/app/settings.py index 0587eb329fd2f8dabd7e722a7cfdf4c26099e608..4e567edb69643027d12f83ff16ce97e846df35c3 100644 --- a/app/settings.py +++ b/app/settings.py @@ -91,6 +91,9 @@ CSENTRY_ENVIRONMENT = "staging" AWX_URL = "https://torn.tn.esss.lu.se" # AWX job templates AWX_CORE_SERVICES_UPDATE = "ics-ans-core @ DHCP test" +# Shall be set to job or workflow_job +# Assumed to be job if the variable is not defined +AWX_CORE_SERVICES_UPDATE_RESOURCE = "job" AWX_CREATE_VM = "deploy-vm-in-proxmox" AWX_CREATE_VIOC = "ics-ans-deploy-vioc" AWX_ZTP_CONFIGURATION = "ics-ans-ztp" diff --git a/app/tasks.py b/app/tasks.py index d260ac3152768e442d8f4662f8f9bcbc2c7dbebf..c861cf43aa1c50455d56ff575d58b79c7f064b25 100644 --- a/app/tasks.py +++ b/app/tasks.py @@ -160,7 +160,14 @@ def trigger_ztp_configuration(host): return task -def launch_job_template(job_template, **kwargs): +def launch_job_template(job_template, resource="job", **kwargs): + """Launch an AWX job or workflow job + + :param job_template: name or id of the job template + :param resource: job|workflow_job + :param **kwargs: keyword arguments passed to launch the job + :returns: A dictionary with information from resource.monitor + """ rq_job = get_current_job() if job_template in ( current_app.config["AWX_CREATE_VIOC"], @@ -172,8 +179,8 @@ def launch_job_template(job_template, **kwargs): current_app.logger.info("AWX job is disabled. Not sending any request.") return "AWX job not triggered" # Launch the AWX job - resource = tower_cli.get_resource("job") - result = resource.launch(job_template=job_template, **kwargs) + resource = tower_cli.get_resource(resource) + result = resource.launch(job_template, **kwargs) # Save the AWX job id in the task task = models.Task.query.get(rq_job.id) task.awx_job_id = result["id"] diff --git a/app/utils.py b/app/utils.py index b05c883ca3c58f6e2972d32a7841f1a787e50c9c..17b2d5e34e6be4f8c8b413d0aab8c1301e1c2492 100644 --- a/app/utils.py +++ b/app/utils.py @@ -240,12 +240,17 @@ def trigger_core_services_update(): Make sure that we don't have more than one in queue. """ job_template = current_app.config["AWX_CORE_SERVICES_UPDATE"] + resource = current_app.config.get("AWX_CORE_SERVICES_UPDATE_RESOURCE", "job") if current_user.is_task_waiting("trigger_core_services_update"): current_app.logger.info( 'Already one "trigger_core_services_update" task waiting. No need to trigger a new one.' ) return None - kwargs = {"func": "launch_job_template", "job_template": job_template} + kwargs = { + "func": "launch_job_template", + "job_template": job_template, + "resource": resource, + } started = current_user.get_task_started("trigger_core_services_update") if started: # There is already one running task. Trigger a new one when it's done.