mirror of
https://github.com/ansible/awx.git
synced 2026-05-20 07:17:40 -02:30
Merge pull request #7245 from sean-m-sullivan/organization_job_template
tower_job_template to use organizations Reviewed-by: https://github.com/apps/softwarefactory-project-zuul
This commit is contained in:
@@ -44,6 +44,14 @@ options:
|
|||||||
description:
|
description:
|
||||||
- Name of the inventory to use for the job template.
|
- Name of the inventory to use for the job template.
|
||||||
type: str
|
type: str
|
||||||
|
organization:
|
||||||
|
description:
|
||||||
|
- Organization the job template exists in.
|
||||||
|
- Used to help lookup the object, cannot be modified using this module.
|
||||||
|
- The Organization is inferred from the associated project
|
||||||
|
- If not provided, will lookup by name only, which does not work with duplicates.
|
||||||
|
- Requires Tower Version 3.7.0 or AWX 10.0.0 IS NOT backwards compatible with earlier versions.
|
||||||
|
type: str
|
||||||
project:
|
project:
|
||||||
description:
|
description:
|
||||||
- Name of the project to use for the job template.
|
- Name of the project to use for the job template.
|
||||||
@@ -282,6 +290,7 @@ EXAMPLES = '''
|
|||||||
tower_job_template:
|
tower_job_template:
|
||||||
name: "Ping"
|
name: "Ping"
|
||||||
job_type: "run"
|
job_type: "run"
|
||||||
|
organization: "Default"
|
||||||
inventory: "Local"
|
inventory: "Local"
|
||||||
project: "Demo"
|
project: "Demo"
|
||||||
playbook: "ping.yml"
|
playbook: "ping.yml"
|
||||||
@@ -332,6 +341,7 @@ def main():
|
|||||||
name=dict(required=True),
|
name=dict(required=True),
|
||||||
new_name=dict(),
|
new_name=dict(),
|
||||||
description=dict(default=''),
|
description=dict(default=''),
|
||||||
|
organization=dict(),
|
||||||
job_type=dict(choices=['run', 'check']),
|
job_type=dict(choices=['run', 'check']),
|
||||||
inventory=dict(),
|
inventory=dict(),
|
||||||
project=dict(),
|
project=dict(),
|
||||||
@@ -398,19 +408,24 @@ def main():
|
|||||||
credentials = []
|
credentials = []
|
||||||
credentials.append(credential)
|
credentials.append(credential)
|
||||||
|
|
||||||
|
new_fields = {}
|
||||||
|
search_fields = {'name': name}
|
||||||
|
|
||||||
|
# Attempt to look up the related items the user specified (these will fail the module if not found)
|
||||||
|
organization_id = None
|
||||||
|
organization = module.params.get('organization')
|
||||||
|
if organization:
|
||||||
|
organization_id = module.resolve_name_to_id('organizations', organization)
|
||||||
|
search_fields['organization'] = new_fields['organization'] = organization_id
|
||||||
|
|
||||||
# Attempt to look up an existing item based on the provided data
|
# Attempt to look up an existing item based on the provided data
|
||||||
existing_item = module.get_one('job_templates', **{
|
existing_item = module.get_one('job_templates', **{'data': search_fields})
|
||||||
'data': {
|
|
||||||
'name': name,
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
if state == 'absent':
|
if state == 'absent':
|
||||||
# If the state was absent we can let the module delete it if needed, the module will handle exiting from this
|
# If the state was absent we can let the module delete it if needed, the module will handle exiting from this
|
||||||
module.delete_if_needed(existing_item)
|
module.delete_if_needed(existing_item)
|
||||||
|
|
||||||
# Create the data that gets sent for create and update
|
# Create the data that gets sent for create and update
|
||||||
new_fields = {}
|
|
||||||
new_fields['name'] = new_name if new_name else name
|
new_fields['name'] = new_name if new_name else name
|
||||||
for field_name in (
|
for field_name in (
|
||||||
'description', 'job_type', 'playbook', 'scm_branch', 'forks', 'limit', 'verbosity',
|
'description', 'job_type', 'playbook', 'scm_branch', 'forks', 'limit', 'verbosity',
|
||||||
@@ -437,7 +452,20 @@ def main():
|
|||||||
if inventory is not None:
|
if inventory is not None:
|
||||||
new_fields['inventory'] = module.resolve_name_to_id('inventories', inventory)
|
new_fields['inventory'] = module.resolve_name_to_id('inventories', inventory)
|
||||||
if project is not None:
|
if project is not None:
|
||||||
new_fields['project'] = module.resolve_name_to_id('projects', project)
|
if organization_id is not None:
|
||||||
|
project_data = module.get_one('projects', **{
|
||||||
|
'data': {
|
||||||
|
'name': project,
|
||||||
|
'organization': organization_id,
|
||||||
|
}
|
||||||
|
})
|
||||||
|
if project_data is None:
|
||||||
|
module.fail_json(msg="The project {0} in organization {1} was not found on the Tower server".format(
|
||||||
|
project, organization
|
||||||
|
))
|
||||||
|
new_fields['project'] = project_data['id']
|
||||||
|
else:
|
||||||
|
new_fields['project'] = module.resolve_name_to_id('projects', project)
|
||||||
if webhook_credential is not None:
|
if webhook_credential is not None:
|
||||||
new_fields['webhook_credential'] = module.resolve_name_to_id('credentials', webhook_credential)
|
new_fields['webhook_credential'] = module.resolve_name_to_id('credentials', webhook_credential)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user