From c57ec1ea79555146a89f5cec36ef12b9efa1e825 Mon Sep 17 00:00:00 2001 From: sean-m-sullivan Date: Sat, 10 Oct 2020 13:25:09 -0500 Subject: [PATCH] update delete --- .../tower_workflow_job_template_node.py | 86 +++++++++---------- 1 file changed, 43 insertions(+), 43 deletions(-) diff --git a/awx_collection/plugins/modules/tower_workflow_job_template_node.py b/awx_collection/plugins/modules/tower_workflow_job_template_node.py index bee8a84a81..af235b958e 100644 --- a/awx_collection/plugins/modules/tower_workflow_job_template_node.py +++ b/awx_collection/plugins/modules/tower_workflow_job_template_node.py @@ -238,54 +238,54 @@ def main(): 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, 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') - if unified_job_template: - new_fields['unified_job_template'] = module.resolve_name_to_id('unified_job_templates', unified_job_template) + inventory = module.params.get('inventory') + if inventory: + new_fields['inventory'] = module.resolve_name_to_id('inventories', inventory) - inventory = module.params.get('inventory') - if inventory: - new_fields['inventory'] = module.resolve_name_to_id('inventories', inventory) + # Create the data that gets sent for create and update + for field_name in ( + '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 - for field_name in ( - '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 + association_fields = {} + for association in ('always_nodes', 'success_nodes', 'failure_nodes', 'credentials'): + 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 - association_fields = {} - for association in ('always_nodes', 'success_nodes', 'failure_nodes', 'credentials'): - 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 + new_fields['type'] = 'workflow_job_template_node' - # In the case of a new object, the utils need to know it is a node - new_fields['type'] = 'workflow_job_template_node' - - # If the state was present and we can let the module build or update the existing item, this will return on its own - module.create_or_update_if_needed( - existing_item, new_fields, - endpoint='workflow_job_template_nodes', item_type='workflow_job_template_node', on_continue=approval_node, - associations=association_fields - ) + # If the state was present and we can let the module build or update the existing item, this will return on its own + module.create_or_update_if_needed( + 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 if approval_node: