diff --git a/awx_collection/plugins/modules/tower_credential.py b/awx_collection/plugins/modules/tower_credential.py index cdda10867a..3aa2343788 100644 --- a/awx_collection/plugins/modules/tower_credential.py +++ b/awx_collection/plugins/modules/tower_credential.py @@ -45,7 +45,7 @@ options: credential_type: description: - Name of credential type. - - Will be prefered over kind + - Will be preferred over kind required: False version_added: "2.10" type: str @@ -340,13 +340,14 @@ def main(): cred_type_id = module.resolve_name_to_id('credential_types', credential_type if credential_type else KIND_CHOICES[kind]) - # Attempt to look up the object based on the provided name and inventory ID - credential = module.get_one('credentials', **{ - 'data': { - 'name': name, - 'credential_type': cred_type_id, - } - }) + # 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}) # Create credential input from legacy inputs credential_inputs = {} 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 42bf108d30..aef37c3ff1 100644 --- a/awx_collection/tests/integration/targets/tower_credential/tasks/main.yml +++ b/awx_collection/tests/integration/targets/tower_credential/tasks/main.yml @@ -42,7 +42,7 @@ organization: Default user: admin kind: ssh - authorize: False + authorize: false authorize_password: 'test' client: 'test' security_token: 'test' @@ -62,7 +62,7 @@ vault_id: 'test' ssh_key_unlock: 'test' state: absent - ignore_errors: True + ignore_errors: true register: result - assert: @@ -125,7 +125,6 @@ - name: Delete a User-specific credential tower_credential: name: "{{ ssh_cred_name1 }}" - organization: Default user: admin state: absent kind: ssh @@ -253,7 +252,7 @@ ssh_key_data: "{{ tempdir.stdout }}/id_rsa" ssh_key_unlock: "passphrase" register: result - ignore_errors: True + ignore_errors: true - assert: that: @@ -353,7 +352,7 @@ description: An example Vault credential vault_password: secret-vault register: result - ignore_errors: True + ignore_errors: true - assert: that: