From e8a95a1dac8fbb3b509ab92142f25d6f857ad11b Mon Sep 17 00:00:00 2001 From: beeankha Date: Tue, 14 Jan 2020 16:28:16 -0500 Subject: [PATCH 1/3] Fail the task if extra_vars is set on launch but ask_extra_vars is not set to True on the Job Template --- awx_collection/plugins/modules/tower_job_launch.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/awx_collection/plugins/modules/tower_job_launch.py b/awx_collection/plugins/modules/tower_job_launch.py index 65566cb316..ac25c5caeb 100644 --- a/awx_collection/plugins/modules/tower_job_launch.py +++ b/awx_collection/plugins/modules/tower_job_launch.py @@ -122,9 +122,17 @@ def update_fields(module, p): params = p.copy() params_update = {} + 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'] + 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) - if extra_vars: + if extra_vars and ask_extra_vars is not True: + module.fail_json(msg="extra_vars is set on launch but the Job Template does not have ask_extra_vars set to True.") + + elif extra_vars: params_update['extra_vars'] = [json.dumps(extra_vars)] params.update(params_update) From db0d74830200dca7e1930017f8ef157a1430623a Mon Sep 17 00:00:00 2001 From: beeankha Date: Wed, 15 Jan 2020 14:38:04 -0500 Subject: [PATCH 2/3] Also check for survey_enabled parameter --- awx_collection/plugins/modules/tower_job_launch.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/awx_collection/plugins/modules/tower_job_launch.py b/awx_collection/plugins/modules/tower_job_launch.py index ac25c5caeb..7b00cd2907 100644 --- a/awx_collection/plugins/modules/tower_job_launch.py +++ b/awx_collection/plugins/modules/tower_job_launch.py @@ -126,14 +126,15 @@ def update_fields(module, p): 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) - if extra_vars and ask_extra_vars is not True: - module.fail_json(msg="extra_vars is set on launch but the Job Template does not have ask_extra_vars set to True.") + if extra_vars and (ask_extra_vars or survey_enabled): + params_update['extra_vars'] = [json.dumps(extra_vars)] elif extra_vars: - params_update['extra_vars'] = [json.dumps(extra_vars)] + module.fail_json(msg="extra_vars is set on launch but the Job Template does not have ask_extra_vars or survey_enabled set to True.") params.update(params_update) return params From fa043100bd102ccd11f6f07ae534fabdb3ecd1e7 Mon Sep 17 00:00:00 2001 From: beeankha Date: Wed, 15 Jan 2020 15:35:29 -0500 Subject: [PATCH 3/3] Add info to changelog --- awx_collection/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/awx_collection/README.md b/awx_collection/README.md index 64705907b0..ae6d466e5e 100644 --- a/awx_collection/README.md +++ b/awx_collection/README.md @@ -21,6 +21,7 @@ The following notes are changes that may require changes to playbooks. - When a project is created, it will wait for the update/sync to finish by default; this can be turned off with the `wait` parameter, if desired. - Creating a "scan" type job template is no longer supported. - `extra_vars` in the `tower_job_launch` module worked with a list previously, but is now configured to work solely in a `dict` format. + - When the `extra_vars` parameter is used with the `tower_job_launch` module, the Job Template launch will fail unless `add_extra_vars` or `survey_enabled` is explicitly set to `True` on the Job Template. ## Running