From 76f03b9adc075203b16b565c793a2cd2cc363530 Mon Sep 17 00:00:00 2001 From: matt Date: Mon, 20 Mar 2023 09:59:24 -0600 Subject: [PATCH] add `exists` to awx.awx.credential --- awx_collection/plugins/modules/credential.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/awx_collection/plugins/modules/credential.py b/awx_collection/plugins/modules/credential.py index 4e7f02e558..75f3a69470 100644 --- a/awx_collection/plugins/modules/credential.py +++ b/awx_collection/plugins/modules/credential.py @@ -87,7 +87,7 @@ options: update_secrets: description: - C(true) will always update encrypted values. - - C(false) will only updated encrypted values if a change is absolutely known to be needed. + - C(false) will only update encrypted values if a change is absolutely known to be needed. type: bool default: true user: @@ -100,8 +100,8 @@ options: type: str state: description: - - Desired state of the resource. - choices: ["present", "absent"] + - Desired state of the resource. C(exists) will not modify the resource if it is present. + choices: ["present", "absent", "exists"] default: "present" type: str @@ -216,7 +216,7 @@ def main(): update_secrets=dict(type='bool', default=True, no_log=False), user=dict(), team=dict(), - state=dict(choices=['present', 'absent'], default='present'), + state=dict(choices=['present', 'absent', 'exists'], default='present'), ) # Create a module for ourselves @@ -265,6 +265,10 @@ def main(): # 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(credential) + if state == 'exists' and credential is not None: + # If credential exists and state is exists, we're done here. + module.create_if_needed(credential, credential, endpoint='credentials', item_type='credential') + # Attempt to look up the related items the user specified (these will fail the module if not found) if user: user_id = module.resolve_name_to_id('users', user)