Merge pull request #5694 from beeankha/tower_job_launch_module_exception

Fail Gracefully on tower_job_launch Module When JT is Not Found

Reviewed-by: https://github.com/apps/softwarefactory-project-zuul
This commit is contained in:
softwarefactory-project-zuul[bot] 2020-01-17 23:46:49 +00:00 committed by GitHub
commit 08a195ba08
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -125,10 +125,12 @@ def update_fields(module, p):
job_template = params.get('job_template')
extra_vars = params.get('extra_vars')
try:
ask_extra_vars = tower_cli.get_resource('job_template').get(name=job_template)['ask_variables_on_launch']
survey_enabled = tower_cli.get_resource('job_template').get(name=job_template)['survey_enabled']
except (exc.ConnectionError, exc.BadRequest, exc.AuthError) as excinfo:
module.fail_json(msg='Failed to get ask_extra_vars parameter, job template not found: {0}'.format(excinfo), changed=False)
job_template_to_launch = tower_cli.get_resource('job_template').get(name=job_template)
except (exc.NotFound) as excinfo:
module.fail_json(msg='Unable to launch job, job_template/{0} was not found: {1}'.format(job_template, excinfo), changed=False)
ask_extra_vars = job_template_to_launch['ask_variables_on_launch']
survey_enabled = job_template_to_launch['survey_enabled']
if extra_vars and (ask_extra_vars or survey_enabled):
params_update['extra_vars'] = [json.dumps(extra_vars)]