From 24ec12923578540f80f1be3440466c06a467f53e Mon Sep 17 00:00:00 2001 From: John Westcott IV Date: Thu, 3 Sep 2020 11:17:21 -0400 Subject: [PATCH] Modifying credential for new get_one --- awx_collection/plugins/modules/tower_credential.py | 5 +++-- .../integration/targets/tower_credential/tasks/main.yml | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/awx_collection/plugins/modules/tower_credential.py b/awx_collection/plugins/modules/tower_credential.py index 2d4cbd3331..3f37e0ad62 100644 --- a/awx_collection/plugins/modules/tower_credential.py +++ b/awx_collection/plugins/modules/tower_credential.py @@ -365,13 +365,14 @@ def main(): # Attempt to look up the object based on the provided name, credential type and optional organization lookup_data = { - 'name': name, 'credential_type': cred_type_id, } if organization: lookup_data['organization'] = org_id - credential = module.get_one('credentials', **{'data': lookup_data}) + credential = module.get_one('credentials', name_or_id=name, **{'data': lookup_data}) + # If we got an item back make sure the name field reflects the actual name (incase we were passed an ID) + name = credential['name'] if (credential) else name if state == 'absent': # If the state was absent we can let the module delete it if needed, the module will handle exiting from this 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 7c0f4b080d..16eac5b66a 100644 --- a/awx_collection/tests/integration/targets/tower_credential/tasks/main.yml +++ b/awx_collection/tests/integration/targets/tower_credential/tasks/main.yml @@ -82,9 +82,9 @@ that: - "result is changed" -- name: Re-create the Org-specific credential (new school) +- name: Re-create the Org-specific credential (new school) with an ID tower_credential: - name: "{{ ssh_cred_name1 }}" + name: "{{ result.id }}" organization: Default credential_type: 'Machine' state: present