mirror of
https://github.com/ansible/awx.git
synced 2026-05-11 03:17:38 -02:30
add logic for survey
This commit is contained in:
@@ -211,7 +211,6 @@ def main():
|
|||||||
check_vars_to_prompts = {
|
check_vars_to_prompts = {
|
||||||
'scm_branch': 'ask_scm_branch_on_launch',
|
'scm_branch': 'ask_scm_branch_on_launch',
|
||||||
'diff_mode': 'ask_diff_mode_on_launch',
|
'diff_mode': 'ask_diff_mode_on_launch',
|
||||||
'extra_vars': 'ask_variables_on_launch',
|
|
||||||
'limit': 'ask_limit_on_launch',
|
'limit': 'ask_limit_on_launch',
|
||||||
'tags': 'ask_tags_on_launch',
|
'tags': 'ask_tags_on_launch',
|
||||||
'skip_tags': 'ask_skip_tags_on_launch',
|
'skip_tags': 'ask_skip_tags_on_launch',
|
||||||
@@ -225,6 +224,9 @@ def main():
|
|||||||
for variable_name in check_vars_to_prompts:
|
for variable_name in check_vars_to_prompts:
|
||||||
if module.params.get(variable_name) and not job_template[check_vars_to_prompts[variable_name]]:
|
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))
|
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:
|
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})
|
module.fail_json(msg="Parameters specified which can not be passed into job template, see errors for details", **{'errors': param_errors})
|
||||||
|
|
||||||
|
|||||||
@@ -152,15 +152,17 @@ def main():
|
|||||||
'inventory': 'ask_inventory_on_launch',
|
'inventory': 'ask_inventory_on_launch',
|
||||||
'limit': 'ask_limit_on_launch',
|
'limit': 'ask_limit_on_launch',
|
||||||
'scm_branch': 'ask_scm_branch_on_launch',
|
'scm_branch': 'ask_scm_branch_on_launch',
|
||||||
'extra_vars': 'ask_variables_on_launch',
|
|
||||||
}
|
}
|
||||||
|
|
||||||
param_errors = []
|
param_errors = []
|
||||||
for variable_name in check_vars_to_prompts:
|
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]]:
|
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))
|
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:
|
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
|
# Launch the job
|
||||||
result = module.post_endpoint(workflow_job_template['related']['launch'], data=post_data)
|
result = module.post_endpoint(workflow_job_template['related']['launch'], data=post_data)
|
||||||
|
|||||||
@@ -70,12 +70,84 @@
|
|||||||
scm_type: git
|
scm_type: git
|
||||||
scm_url: https://github.com/ansible/test-playbooks
|
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
|
- name: Create a Job Template for testing extra_vars
|
||||||
tower_job_template:
|
tower_job_template:
|
||||||
name: "{{ jt_name2 }}"
|
name: "{{ jt_name2 }}"
|
||||||
project: "{{ proj_name }}"
|
project: "{{ proj_name }}"
|
||||||
playbook: debug.yml
|
playbook: debug.yml
|
||||||
job_type: run
|
job_type: run
|
||||||
|
survey_enabled: false
|
||||||
state: present
|
state: present
|
||||||
inventory: "Demo Inventory"
|
inventory: "Demo Inventory"
|
||||||
extra_vars:
|
extra_vars:
|
||||||
|
|||||||
@@ -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
|
||||||
@@ -66,6 +66,66 @@
|
|||||||
- result is not failed
|
- result is not failed
|
||||||
- "'id' in result['job_info']"
|
- "'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
|
- name: Prompt the workflow's extra_vars on launch
|
||||||
tower_workflow_job_template:
|
tower_workflow_job_template:
|
||||||
name: "{{ wfjt_name1 }}"
|
name: "{{ wfjt_name1 }}"
|
||||||
@@ -76,6 +136,7 @@
|
|||||||
tower_workflow_launch:
|
tower_workflow_launch:
|
||||||
workflow_template: "{{ wfjt_name1 }}"
|
workflow_template: "{{ wfjt_name1 }}"
|
||||||
extra_vars:
|
extra_vars:
|
||||||
|
basic_name: My First Variable
|
||||||
var1: My First Variable
|
var1: My First Variable
|
||||||
var2: My Second Variable
|
var2: My Second Variable
|
||||||
ignore_errors: true
|
ignore_errors: true
|
||||||
|
|||||||
@@ -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
|
||||||
Reference in New Issue
Block a user