mirror of
https://github.com/ZwareBear/awx.git
synced 2026-05-13 02:28:36 -05:00
update logic
This commit is contained in:
@@ -224,37 +224,17 @@ def main():
|
||||
organization_id = module.resolve_name_to_id('organizations', organization)
|
||||
search_fields['organization'] = new_fields['organization'] = organization_id
|
||||
|
||||
# Attempt to look up workflow job template to copy based on the provided name
|
||||
if copy_from:
|
||||
# Check if workflow job template exists, as API will allow you to create an identical item with the same name in same org, but GUI will not.
|
||||
workflow_job_template = module.get_one('workflow_job_templates', name_or_id=name, data=search_fields)
|
||||
if workflow_job_template is not None:
|
||||
module.fail_json(msg="A workflow job template with the name {0} already exists.".format(name))
|
||||
else:
|
||||
# Lookup existing workflow job template.
|
||||
copy_from_lookup = module.get_one('workflow_job_templates', name_or_id=copy_from)
|
||||
if copy_from_lookup is None:
|
||||
module.fail_json(msg="A workflow job template with the name {0} was not able to be found.".format(copy_from))
|
||||
else:
|
||||
workflow_copy_get_check = module.get_endpoint(copy_from_lookup['related']['copy'])
|
||||
if workflow_copy_get_check['status_code'] in [200]:
|
||||
if (workflow_copy_get_check['json']['can_copy'] and workflow_copy_get_check['json']['can_copy_without_user_input'] and
|
||||
not workflow_copy_get_check['json']['templates_unable_to_copy'] and not workflow_copy_get_check['json']['credentials_unable_to_copy']
|
||||
and not workflow_copy_get_check['json']['inventories_unable_to_copy']):
|
||||
# Because the initial copy will keep its organization, this can be different then the specified one.
|
||||
search_fields['organization'] = copy_from_lookup['organization']
|
||||
module.copy_item(
|
||||
copy_from_lookup, name,
|
||||
item_type='workflow_job_template'
|
||||
)
|
||||
else:
|
||||
module.fail_json(msg="Unable to copy workflow {0} error: {1}".format(copy_from, workflow_copy_get_check))
|
||||
else:
|
||||
module.fail_json(msg="Error accessing workflow {0} error: {1} ".format(copy_from, workflow_copy_get_check))
|
||||
|
||||
# Attempt to look up an existing item based on the provided data
|
||||
existing_item = module.get_one('workflow_job_templates', name_or_id=name, **{'data': search_fields})
|
||||
|
||||
# Attempt to look up credential to copy based on the provided name
|
||||
if copy_from:
|
||||
# a new existing item is formed when copying and is returned.
|
||||
existing_item = module.copy_item(
|
||||
existing_item, copy_from, name,
|
||||
endpoint='workflow_job_templates', item_type='workflow_job_template',
|
||||
)
|
||||
|
||||
if state == 'absent':
|
||||
# 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)
|
||||
|
||||
Reference in New Issue
Block a user