update delete

This commit is contained in:
sean-m-sullivan
2020-10-10 13:25:09 -05:00
parent c3045f6a29
commit c57ec1ea79

View File

@@ -238,54 +238,54 @@ def main():
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, on_continue=True,) module.delete_if_needed(existing_item, on_continue=True,)
else:
unified_job_template = module.params.get('unified_job_template')
if unified_job_template:
new_fields['unified_job_template'] = module.resolve_name_to_id('unified_job_templates', unified_job_template)
unified_job_template = module.params.get('unified_job_template') inventory = module.params.get('inventory')
if unified_job_template: if inventory:
new_fields['unified_job_template'] = module.resolve_name_to_id('unified_job_templates', unified_job_template) new_fields['inventory'] = module.resolve_name_to_id('inventories', inventory)
inventory = module.params.get('inventory') # Create the data that gets sent for create and update
if inventory: for field_name in (
new_fields['inventory'] = module.resolve_name_to_id('inventories', inventory) 'identifier', 'extra_data', 'scm_branch', 'job_type', 'job_tags', 'skip_tags',
'limit', 'diff_mode', 'verbosity', 'all_parents_must_converge',):
field_val = module.params.get(field_name)
if field_val:
new_fields[field_name] = field_val
# Create the data that gets sent for create and update association_fields = {}
for field_name in ( for association in ('always_nodes', 'success_nodes', 'failure_nodes', 'credentials'):
'identifier', 'extra_data', 'scm_branch', 'job_type', 'job_tags', 'skip_tags', name_list = module.params.get(association)
'limit', 'diff_mode', 'verbosity', 'all_parents_must_converge',): if name_list is None:
field_val = module.params.get(field_name) continue
if field_val: id_list = []
new_fields[field_name] = field_val for sub_name in name_list:
if association == 'credentials':
endpoint = 'credentials'
lookup_data = {'name': sub_name}
else:
endpoint = 'workflow_job_template_nodes'
lookup_data = {'identifier': sub_name}
if workflow_job_template_id:
lookup_data['workflow_job_template'] = workflow_job_template_id
sub_obj = module.get_one(endpoint, **{'data': lookup_data})
if sub_obj is None:
module.fail_json(msg='Could not find {0} entry with name {1}'.format(association, sub_name))
id_list.append(sub_obj['id'])
if id_list:
association_fields[association] = id_list
association_fields = {} # In the case of a new object, the utils need to know it is a node
for association in ('always_nodes', 'success_nodes', 'failure_nodes', 'credentials'): new_fields['type'] = 'workflow_job_template_node'
name_list = module.params.get(association)
if name_list is None:
continue
id_list = []
for sub_name in name_list:
if association == 'credentials':
endpoint = 'credentials'
lookup_data = {'name': sub_name}
else:
endpoint = 'workflow_job_template_nodes'
lookup_data = {'identifier': sub_name}
if workflow_job_template_id:
lookup_data['workflow_job_template'] = workflow_job_template_id
sub_obj = module.get_one(endpoint, **{'data': lookup_data})
if sub_obj is None:
module.fail_json(msg='Could not find {0} entry with name {1}'.format(association, sub_name))
id_list.append(sub_obj['id'])
if id_list:
association_fields[association] = id_list
# In the case of a new object, the utils need to know it is a node # If the state was present and we can let the module build or update the existing item, this will return on its own
new_fields['type'] = 'workflow_job_template_node' module.create_or_update_if_needed(
existing_item, new_fields,
# If the state was present and we can let the module build or update the existing item, this will return on its own endpoint='workflow_job_template_nodes', item_type='workflow_job_template_node', on_continue=approval_node,
module.create_or_update_if_needed( associations=association_fields
existing_item, new_fields, )
endpoint='workflow_job_template_nodes', item_type='workflow_job_template_node', on_continue=approval_node,
associations=association_fields
)
# Create approval node unified template or update existing # Create approval node unified template or update existing
if approval_node: if approval_node: