From 666e9c5c2f26206c512fd62ab3c94eea78ba4b43 Mon Sep 17 00:00:00 2001 From: sean-m-ssullivan Date: Wed, 28 Apr 2021 17:48:57 -0500 Subject: [PATCH] add search label by org --- .../plugins/modules/tower_job_template.py | 9 ++------ .../modules/tower_workflow_job_template.py | 9 ++------ .../targets/tower_job_template/tasks/main.yml | 22 ++++++++++++++++-- .../tasks/main.yml | 23 +++++++++++++++++-- 4 files changed, 45 insertions(+), 18 deletions(-) diff --git a/awx_collection/plugins/modules/tower_job_template.py b/awx_collection/plugins/modules/tower_job_template.py index 41e6cbfc3b..9b25ed4f8e 100644 --- a/awx_collection/plugins/modules/tower_job_template.py +++ b/awx_collection/plugins/modules/tower_job_template.py @@ -544,13 +544,8 @@ def main(): if labels is not None: association_fields['labels'] = [] for item in labels: - association_fields['labels'].append(module.resolve_name_to_id('labels', item)) - # Code to use once Issue #7567 is resolved - # search_fields = {'name': item} - # if organization: - # search_fields['organization'] = organization_id - # label_id = module.get_one('labels', **{'data': search_fields}) - # association_fields['labels'].append(label_id) + label_id = module.get_one('labels', name_or_id=item, **{'data': search_fields}) + association_fields['labels'].append(label_id['id']) notifications_start = module.params.get('notification_templates_started') if notifications_start is not None: diff --git a/awx_collection/plugins/modules/tower_workflow_job_template.py b/awx_collection/plugins/modules/tower_workflow_job_template.py index 2febda3b04..061b3912be 100644 --- a/awx_collection/plugins/modules/tower_workflow_job_template.py +++ b/awx_collection/plugins/modules/tower_workflow_job_template.py @@ -795,13 +795,8 @@ def main(): if labels is not None: association_fields['labels'] = [] for item in labels: - association_fields['labels'].append(module.resolve_name_to_id('labels', item)) - # Code to use once Issue #7567 is resolved - # search_fields = {'name': item} - # if organization: - # search_fields['organization'] = organization_id - # label_id = module.get_one('labels', **{'data': search_fields}) - # association_fields['labels'].append(label_id) + label_id = module.get_one('labels', name_or_id=item, **{'data': search_fields}) + association_fields['labels'].append(label_id['id']) on_change = None new_spec = module.params.get('survey_spec') diff --git a/awx_collection/tests/integration/targets/tower_job_template/tasks/main.yml b/awx_collection/tests/integration/targets/tower_job_template/tasks/main.yml index 3b56bc9094..6ad195732b 100644 --- a/awx_collection/tests/integration/targets/tower_job_template/tasks/main.yml +++ b/awx_collection/tests/integration/targets/tower_job_template/tasks/main.yml @@ -5,6 +5,7 @@ - name: generate random string for project set_fact: + org_name: "AWX-Collection-tests-tower_organization-org-{{ test_id }}" cred1: "AWX-Collection-tests-tower_job_template-cred1-{{ test_id }}" cred2: "AWX-Collection-tests-tower_job_template-cred2-{{ test_id }}" cred3: "AWX-Collection-tests-tower_job_template-cred3-{{ test_id }}" @@ -16,6 +17,13 @@ webhook_not: "AWX-Collection-tests-tower_notification_template-wehbook-not-{{ test_id }}" group_name1: "AWX-Collection-tests-tower_instance_group-group1-{{ test_id }}" +- name: "Create a new organization" + tower_organization: + name: "{{ org_name }}" + galaxy_credentials: + - Ansible Galaxy + register: result + - name: Create a Demo Project tower_project: name: "{{ proj1 }}" @@ -44,10 +52,13 @@ organization: Default kind: ssh -- name: Create Label +- name: Create Labels tower_label: name: "{{ lab1 }}" - organization: Default + organization: "{{ item }}" + loop: + - Default + - "{{ org_name }}" - name: Create an Instance Group tower_instance_group: @@ -202,6 +213,7 @@ - name: Create Job Template 2 tower_job_template: name: "{{ jt2 }}" + organization: Default project: "{{ proj1 }}" inventory: Demo Inventory playbook: hello_world.yml @@ -409,3 +421,9 @@ name: "{{ webhook_not }}" organization: Default state: absent + +- name: "Remove the organization" + tower_organization: + name: "{{ org_name }}" + state: absent + register: result diff --git a/awx_collection/tests/integration/targets/tower_workflow_job_template/tasks/main.yml b/awx_collection/tests/integration/targets/tower_workflow_job_template/tasks/main.yml index cb8be5a06b..8741f0cb1b 100644 --- a/awx_collection/tests/integration/targets/tower_workflow_job_template/tasks/main.yml +++ b/awx_collection/tests/integration/targets/tower_workflow_job_template/tasks/main.yml @@ -5,6 +5,7 @@ - name: Generate random names for test objects set_fact: + org_name: "AWX-Collection-tests-tower_organization-org-{{ test_id }}" scm_cred_name: "AWX-Collection-tests-tower_workflow_job_template-scm-cred-{{ test_id }}" demo_project_name: "AWX-Collection-tests-tower_workflow_job_template-proj-{{ test_id }}" jt1_name: "AWX-Collection-tests-tower_workflow_job_template-jt1-{{ test_id }}" @@ -17,6 +18,13 @@ project_inv: "AWX-Collection-tests-tower_inventory_source-inv-project-{{ lookup('password', '/dev/null chars=ascii_letters length=16') }}" project_inv_source: "AWX-Collection-tests-tower_inventory_source-inv-source-project-{{ lookup('password', '/dev/null chars=ascii_letters length=16') }}" +- name: "Create a new organization" + tower_organization: + name: "{{ org_name }}" + galaxy_credentials: + - Ansible Galaxy + register: result + - name: Create an SCM Credential tower_credential: name: "{{ scm_cred_name }}" @@ -55,10 +63,13 @@ state: present register: result -- name: Create Label +- name: Create Labels tower_label: name: "{{ lab1 }}" - organization: Default + organization: "{{ item }}" + loop: + - Default + - "{{ org_name }}" - name: Create a Demo Project tower_project: @@ -126,6 +137,7 @@ - name: Add a Survey to second Job Template tower_job_template: name: "{{ jt2_name }}" + organization: Default project: "{{ demo_project_name }}" inventory: Demo Inventory playbook: hello_world.yml @@ -142,6 +154,7 @@ - name: Create a workflow job template tower_workflow_job_template: name: "{{ wfjt_name }}" + organization: Default inventory: Demo Inventory extra_vars: {'foo': 'bar', 'another-foo': {'barz': 'bar2'}} labels: @@ -652,3 +665,9 @@ name: "{{ webhook_not }}" organization: Default state: absent + +- name: "Remove the organization" + tower_organization: + name: "{{ org_name }}" + state: absent + register: result