diff --git a/awx_collection/plugins/module_utils/tower_api.py b/awx_collection/plugins/module_utils/tower_api.py index ce96e492db..4569d221da 100644 --- a/awx_collection/plugins/module_utils/tower_api.py +++ b/awx_collection/plugins/module_utils/tower_api.py @@ -413,7 +413,10 @@ class TowerAPIModule(TowerModule): def copy_item(self, existing_item, copy_from_name_or_id, new_item_name, endpoint=None, item_type='unknown', copy_lookup_data={}): if existing_item is not None: - self.fail_json(msg="A {0} with the name {1} already exists.".format(item_type, new_item_name)) + self.warn(msg="A {0} with the name {1} already exists.".format(item_type, new_item_name)) + self.json_output['changed'] = False + self.json_output['copied'] = False + return existing_item # Lookup existing item to copy from copy_from_lookup = self.get_one(endpoint, name_or_id=copy_from_name_or_id, **{'data': copy_lookup_data}) @@ -441,6 +444,7 @@ class TowerAPIModule(TowerModule): if response['status_code'] in [201]: self.json_output['id'] = response['json']['id'] self.json_output['changed'] = True + self.json_output['copied'] = True new_existing_item = response['json'] else: if 'json' in response and '__all__' in response['json']: diff --git a/awx_collection/tests/integration/targets/tower_credential/tasks/main.yml b/awx_collection/tests/integration/targets/tower_credential/tasks/main.yml index 32a8f95f62..17d4785602 100644 --- a/awx_collection/tests/integration/targets/tower_credential/tasks/main.yml +++ b/awx_collection/tests/integration/targets/tower_credential/tasks/main.yml @@ -212,7 +212,7 @@ - assert: that: - - result is changed + - result.copied - name: Delete an SSH credential tower_credential: diff --git a/awx_collection/tests/integration/targets/tower_inventory/tasks/main.yml b/awx_collection/tests/integration/targets/tower_inventory/tasks/main.yml index 353bdee673..234f2f15a4 100644 --- a/awx_collection/tests/integration/targets/tower_inventory/tasks/main.yml +++ b/awx_collection/tests/integration/targets/tower_inventory/tasks/main.yml @@ -59,7 +59,7 @@ - assert: that: - - "result is changed" + - result.copied - name: Delete an Inventory tower_inventory: diff --git a/awx_collection/tests/integration/targets/tower_notification_template/tasks/main.yml b/awx_collection/tests/integration/targets/tower_notification_template/tasks/main.yml index 0d1f6478d4..af43b7d325 100644 --- a/awx_collection/tests/integration/targets/tower_notification_template/tasks/main.yml +++ b/awx_collection/tests/integration/targets/tower_notification_template/tasks/main.yml @@ -142,7 +142,7 @@ - assert: that: - - result is changed + - result.copied - name: Delete copied email notification tower_notification_template: diff --git a/awx_collection/tests/integration/targets/tower_project/tasks/main.yml b/awx_collection/tests/integration/targets/tower_project/tasks/main.yml index 8a701984ac..95d66c1c51 100644 --- a/awx_collection/tests/integration/targets/tower_project/tasks/main.yml +++ b/awx_collection/tests/integration/targets/tower_project/tasks/main.yml @@ -89,7 +89,7 @@ # the project, or it could be because the module actually failed somehow - assert: that: - - "result is changed" + - result.copied - name: Check module fails with correct msg when given non-existing org as param tower_project: 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 8ef01658dd..b9e413de1f 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 @@ -253,7 +253,7 @@ - assert: that: - - "result is changed" + - result.copied - name: Fail Remove "on start" webhook notification from copied workflow job template tower_workflow_job_template: