mirror of
https://github.com/ansible/awx.git
synced 2026-02-04 02:58:13 -03:30
@@ -37,6 +37,12 @@ options:
|
||||
description:
|
||||
- Inventory to use for the job, only used if prompt for inventory is set.
|
||||
type: str
|
||||
organization:
|
||||
description:
|
||||
- Organization the job template exists in.
|
||||
- Used to help lookup the object, cannot be modified using this module.
|
||||
- If not provided, will lookup by name only, which does not work with duplicates.
|
||||
type: str
|
||||
credentials:
|
||||
description:
|
||||
- Credential to use for job, only used if prompt for credential is set.
|
||||
@@ -149,6 +155,7 @@ def main():
|
||||
name=dict(required=True, aliases=['job_template']),
|
||||
job_type=dict(choices=['run', 'check']),
|
||||
inventory=dict(default=None),
|
||||
organization=dict(),
|
||||
# Credentials will be a str instead of a list for backwards compatability
|
||||
credentials=dict(type='list', default=None, aliases=['credential'], elements='str'),
|
||||
limit=dict(),
|
||||
@@ -172,6 +179,7 @@ def main():
|
||||
name = module.params.get('name')
|
||||
optional_args['job_type'] = module.params.get('job_type')
|
||||
inventory = module.params.get('inventory')
|
||||
organization = module.params.get('organization')
|
||||
credentials = module.params.get('credentials')
|
||||
optional_args['limit'] = module.params.get('limit')
|
||||
optional_args['tags'] = module.params.get('tags')
|
||||
@@ -201,7 +209,10 @@ def main():
|
||||
post_data['credentials'].append(module.resolve_name_to_id('credentials', credential))
|
||||
|
||||
# Attempt to look up job_template based on the provided name
|
||||
job_template = module.get_one('job_templates', name_or_id=name)
|
||||
lookup_data = {}
|
||||
if organization:
|
||||
lookup_data['organization'] = module.resolve_name_to_id('organizations', organization)
|
||||
job_template = module.get_one('job_templates', name_or_id=name, data=lookup_data)
|
||||
|
||||
if job_template is None:
|
||||
module.fail_json(msg="Unable to find job template by name {0}".format(name))
|
||||
@@ -211,7 +222,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 +235,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})
|
||||
|
||||
|
||||
@@ -38,7 +38,7 @@ RETURN = ''' # '''
|
||||
|
||||
EXAMPLES = '''
|
||||
- name: Set the license using a file
|
||||
license:
|
||||
tower_license:
|
||||
manifest: "/tmp/my_manifest.zip"
|
||||
eula_accepted: True
|
||||
'''
|
||||
|
||||
@@ -34,7 +34,7 @@ options:
|
||||
scm_type:
|
||||
description:
|
||||
- Type of SCM resource.
|
||||
choices: ["manual", "git", "hg", "svn", "insights"]
|
||||
choices: ["manual", "git", "svn", "insights"]
|
||||
default: "manual"
|
||||
type: str
|
||||
scm_url:
|
||||
@@ -168,7 +168,7 @@ EXAMPLES = '''
|
||||
organization: "test"
|
||||
scm_update_on_launch: True
|
||||
scm_update_cache_timeout: 60
|
||||
custom_virtualenv: "/var/lib/awx/venv/ansible-2.2"
|
||||
custom_virtualenv: "/var/lib/awx/var/lib/awx/venv/ansible-2.2"
|
||||
state: present
|
||||
tower_config_file: "~/tower_cli.cfg"
|
||||
'''
|
||||
@@ -220,7 +220,7 @@ def main():
|
||||
argument_spec = dict(
|
||||
name=dict(required=True),
|
||||
description=dict(),
|
||||
scm_type=dict(choices=['manual', 'git', 'hg', 'svn', 'insights'], default='manual'),
|
||||
scm_type=dict(choices=['manual', 'git', 'svn', 'insights'], default='manual'),
|
||||
scm_url=dict(),
|
||||
local_path=dict(),
|
||||
scm_branch=dict(default=''),
|
||||
|
||||
@@ -94,10 +94,12 @@ options:
|
||||
- Setting that variable will prompt the user for job type on the
|
||||
workflow launch.
|
||||
type: bool
|
||||
survey:
|
||||
survey_spec:
|
||||
description:
|
||||
- The definition of the survey associated to the workflow.
|
||||
type: dict
|
||||
aliases:
|
||||
- survey
|
||||
labels:
|
||||
description:
|
||||
- The labels applied to this job template
|
||||
@@ -149,7 +151,15 @@ import json
|
||||
|
||||
def update_survey(module, last_request):
|
||||
spec_endpoint = last_request.get('related', {}).get('survey_spec')
|
||||
module.post_endpoint(spec_endpoint, **{'data': module.params.get('survey')})
|
||||
if module.params.get('survey_spec') == {}:
|
||||
response = module.delete_endpoint(spec_endpoint)
|
||||
if response['status_code'] != 200:
|
||||
# Not sure how to make this actually return a non 200 to test what to dump in the respinse
|
||||
module.fail_json(msg="Failed to delete survey: {0}".format(response['json']))
|
||||
else:
|
||||
response = module.post_endpoint(spec_endpoint, **{'data': module.params.get('survey_spec')})
|
||||
if response['status_code'] != 200:
|
||||
module.fail_json(msg="Failed to update survey: {0}".format(response['json']['error']))
|
||||
module.exit_json(**module.json_output)
|
||||
|
||||
|
||||
@@ -161,7 +171,7 @@ def main():
|
||||
description=dict(),
|
||||
extra_vars=dict(type='dict'),
|
||||
organization=dict(),
|
||||
survey=dict(type='dict'), # special handling
|
||||
survey_spec=dict(type='dict', aliases=['survey']),
|
||||
survey_enabled=dict(type='bool'),
|
||||
allow_simultaneous=dict(type='bool'),
|
||||
ask_variables_on_launch=dict(type='bool'),
|
||||
@@ -266,7 +276,7 @@ def main():
|
||||
# association_fields['labels'].append(label_id)
|
||||
|
||||
on_change = None
|
||||
new_spec = module.params.get('survey')
|
||||
new_spec = module.params.get('survey_spec')
|
||||
if new_spec:
|
||||
existing_spec = None
|
||||
if existing_item:
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user