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 diff --git a/awx_collection/plugins/modules/tower_job_launch.py b/awx_collection/plugins/modules/tower_job_launch.py index 65566cb316..7b00cd2907 100644 --- a/awx_collection/plugins/modules/tower_job_launch.py +++ b/awx_collection/plugins/modules/tower_job_launch.py @@ -122,11 +122,20 @@ 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'] + 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: + if extra_vars and (ask_extra_vars or survey_enabled): params_update['extra_vars'] = [json.dumps(extra_vars)] + elif 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