summaryrefslogtreecommitdiffstats
path: root/awx_collection
diff options
context:
space:
mode:
Diffstat (limited to 'awx_collection')
-rw-r--r--awx_collection/plugins/modules/tower_job_launch.py4
-rw-r--r--awx_collection/plugins/modules/tower_workflow_launch.py6
-rw-r--r--awx_collection/tests/integration/targets/tower_job_launch/tasks/main.yml72
-rw-r--r--awx_collection/tests/integration/targets/tower_job_launch/tasks/play.yml15
-rw-r--r--awx_collection/tests/integration/targets/tower_workflow_launch/tasks/main.yml61
-rw-r--r--awx_collection/tests/integration/targets/tower_workflow_launch/tasks/play.yml15
6 files changed, 170 insertions, 3 deletions
diff --git a/awx_collection/plugins/modules/tower_job_launch.py b/awx_collection/plugins/modules/tower_job_launch.py
index 9b118afcec..fe6449fd8b 100644
--- a/awx_collection/plugins/modules/tower_job_launch.py
+++ b/awx_collection/plugins/modules/tower_job_launch.py
@@ -211,7 +211,6 @@ def main():
check_vars_to_prompts = {
'scm_branch': 'ask_scm_branch_on_launch',
'diff_mode': 'ask_diff_mode_on_launch',
- 'extra_vars': 'ask_variables_on_launch',
'limit': 'ask_limit_on_launch',
'tags': 'ask_tags_on_launch',
'skip_tags': 'ask_skip_tags_on_launch',
@@ -225,6 +224,9 @@ def main():
for variable_name in check_vars_to_prompts:
if module.params.get(variable_name) and not job_template[check_vars_to_prompts[variable_name]]:
param_errors.append("The field {0} was specified but the job template does not allow for it to be overridden".format(variable_name))
+ # Check if Either ask_variables_on_launch, or survey_enabled is enabled for use of extra vars.
+ if ( module.params.get('extra_vars') and not (job_template['ask_variables_on_launch'] or job_template['survey_enabled']):
+ param_errors.append("The field extra_vars was specified but the job template does not allow for it to be overridden")
if len(param_errors) > 0:
module.fail_json(msg="Parameters specified which can not be passed into job template, see errors for details", **{'errors': param_errors})
diff --git a/awx_collection/plugins/modules/tower_workflow_launch.py b/awx_collection/plugins/modules/tower_workflow_launch.py
index a1de4a46bc..9ccfbc5c1e 100644
--- a/awx_collection/plugins/modules/tower_workflow_launch.py
+++ b/awx_collection/plugins/modules/tower_workflow_launch.py
@@ -152,15 +152,17 @@ def main():
'inventory': 'ask_inventory_on_launch',
'limit': 'ask_limit_on_launch',
'scm_branch': 'ask_scm_branch_on_launch',
- 'extra_vars': 'ask_variables_on_launch',
}
param_errors = []
for variable_name in check_vars_to_prompts:
if variable_name in post_data and not workflow_job_template[check_vars_to_prompts[variable_name]]:
param_errors.append("The field {0} was specified but the workflow job template does not allow for it to be overridden".format(variable_name))
+ # Check if Either ask_variables_on_launch, or survey_enabled is enabled for use of extra vars.
+ if module.params.get('extra_vars') and not (workflow_job_template['ask_variables_on_launch'] or workflow_job_template['survey_enabled']):
+ param_errors.append("The field extra_vars was specified but the workflow job template does not allow for it to be overridden")
if len(param_errors) > 0:
- module.fail_json(msg="Parameters specified which can not be passed into wotkflow job template, see errors for details", errors=param_errors)
+ module.fail_json(msg="Parameters specified which can not be passed into workflow job template, see errors for details", errors=param_errors)
# Launch the job
result = module.post_endpoint(workflow_job_template['related']['launch'], data=post_data)
diff --git a/awx_collection/tests/integration/targets/tower_job_launch/tasks/main.yml b/awx_collection/tests/integration/targets/tower_job_launch/tasks/main.yml
index c74f6a8bd5..22b31f042f 100644
--- a/awx_collection/tests/integration/targets/tower_job_launch/tasks/main.yml
+++ b/awx_collection/tests/integration/targets/tower_job_launch/tasks/main.yml
@@ -70,12 +70,84 @@
scm_type: git
scm_url: https://github.com/ansible/test-playbooks
+- name: Create the job template with survey
+ tower_job_template:
+ name: "{{ jt_name2 }}"
+ project: "{{ proj_name }}"
+ playbook: debug.yml
+ job_type: run
+ state: present
+ inventory: "Demo Inventory"
+ survey_enabled: true
+ ask_variables_on_launch: false
+ survey_spec:
+ name: ''
+ description: ''
+ spec:
+ - question_name: Basic Name
+ question_description: Name
+ required: true
+ type: text
+ variable: basic_name
+ min: 0
+ max: 1024
+ default: ''
+ choices: ''
+ new_question: true
+ - question_name: Choose yes or no?
+ question_description: Choosing yes or no.
+ required: false
+ type: multiplechoice
+ variable: option_true_false
+ min:
+ max:
+ default: 'yes'
+ choices: |-
+ yes
+ no
+ new_question: true
+
+- name: Kick off a job template with survey
+ tower_job_launch:
+ job_template: "{{ jt_name2 }}"
+ extra_vars:
+ basic_name: My First Variable
+ option_true_false: 'no'
+ ignore_errors: true
+ register: result
+
+- assert:
+ that:
+ - result is not failed
+
+- name: Prompt the job templates extra_vars on launch
+ tower_job_template:
+ name: "{{ jt_name2 }}"
+ state: present
+ ask_variables_on_launch: true
+
+
+- name: Kick off a job template with extra_vars
+ tower_job_launch:
+ job_template: "{{ jt_name2 }}"
+ extra_vars:
+ basic_name: My First Variable
+ var1: My First Variable
+ var2: My Second Variable
+ ignore_errors: true
+ register: result
+
+- assert:
+ that:
+ - result is not failed
+
- name: Create a Job Template for testing extra_vars
tower_job_template:
name: "{{ jt_name2 }}"
project: "{{ proj_name }}"
playbook: debug.yml
job_type: run
+ survey_enabled: false
state: present
inventory: "Demo Inventory"
extra_vars:
diff --git a/awx_collection/tests/integration/targets/tower_job_launch/tasks/play.yml b/awx_collection/tests/integration/targets/tower_job_launch/tasks/play.yml
new file mode 100644
index 0000000000..2b10e65417
--- /dev/null
+++ b/awx_collection/tests/integration/targets/tower_job_launch/tasks/play.yml
@@ -0,0 +1,15 @@
+---
+- name: Run Integration Test
+ hosts: localhost
+ connection: local
+ gather_facts: False
+ environment:
+ TOWER_HOST: https://ansible-tower-web-svc-tower.apps-crc.testing
+ TOWER_USERNAME: admin
+ TOWER_PASSWORD: password
+ TOWER_VERIFY_SSL: False
+ collections:
+ - awx.awx
+
+ tasks:
+ - include_tasks: main.yml \ No newline at end of file
diff --git a/awx_collection/tests/integration/targets/tower_workflow_launch/tasks/main.yml b/awx_collection/tests/integration/targets/tower_workflow_launch/tasks/main.yml
index 680b629473..5cd4e06d1e 100644
--- a/awx_collection/tests/integration/targets/tower_workflow_launch/tasks/main.yml
+++ b/awx_collection/tests/integration/targets/tower_workflow_launch/tasks/main.yml
@@ -66,6 +66,66 @@
- result is not failed
- "'id' in result['job_info']"
+- name: Kick off a workflow with extra_vars but not enabled
+ tower_workflow_launch:
+ workflow_template: "{{ wfjt_name1 }}"
+ extra_vars:
+ var1: My First Variable
+ var2: My Second Variable
+ ignore_errors: true
+ register: result
+
+- assert:
+ that:
+ - result is failed
+ - "'The field extra_vars was specified but the workflow job template does not allow for it to be overridden' in result.errors"
+
+- name: Prompt the workflow's with survey
+ tower_workflow_job_template:
+ name: "{{ wfjt_name1 }}"
+ state: present
+ survey_enabled: true
+ ask_variables_on_launch: false
+ survey:
+ name: ''
+ description: ''
+ spec:
+ - question_name: Basic Name
+ question_description: Name
+ required: true
+ type: text
+ variable: basic_name
+ min: 0
+ max: 1024
+ default: ''
+ choices: ''
+ new_question: true
+ - question_name: Choose yes or no?
+ question_description: Choosing yes or no.
+ required: false
+ type: multiplechoice
+ variable: option_true_false
+ min:
+ max:
+ default: 'yes'
+ choices: |-
+ yes
+ no
+ new_question: true
+
+- name: Kick off a workflow with survey
+ tower_workflow_launch:
+ workflow_template: "{{ wfjt_name1 }}"
+ extra_vars:
+ basic_name: My First Variable
+ option_true_false: 'no'
+ ignore_errors: true
+ register: result
+
+- assert:
+ that:
+ - result is not failed
+
- name: Prompt the workflow's extra_vars on launch
tower_workflow_job_template:
name: "{{ wfjt_name1 }}"
@@ -76,6 +136,7 @@
tower_workflow_launch:
workflow_template: "{{ wfjt_name1 }}"
extra_vars:
+ basic_name: My First Variable
var1: My First Variable
var2: My Second Variable
ignore_errors: true
diff --git a/awx_collection/tests/integration/targets/tower_workflow_launch/tasks/play.yml b/awx_collection/tests/integration/targets/tower_workflow_launch/tasks/play.yml
new file mode 100644
index 0000000000..2b10e65417
--- /dev/null
+++ b/awx_collection/tests/integration/targets/tower_workflow_launch/tasks/play.yml
@@ -0,0 +1,15 @@
+---
+- name: Run Integration Test
+ hosts: localhost
+ connection: local
+ gather_facts: False
+ environment:
+ TOWER_HOST: https://ansible-tower-web-svc-tower.apps-crc.testing
+ TOWER_USERNAME: admin
+ TOWER_PASSWORD: password
+ TOWER_VERIFY_SSL: False
+ collections:
+ - awx.awx
+
+ tasks:
+ - include_tasks: main.yml \ No newline at end of file