add exists to awx.awx.credential

This commit is contained in:
matt
2023-03-20 09:59:24 -06:00
parent 46227f14a1
commit 76f03b9adc

View File

@@ -87,7 +87,7 @@ options:
update_secrets: update_secrets:
description: description:
- C(true) will always update encrypted values. - 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 type: bool
default: true default: true
user: user:
@@ -100,8 +100,8 @@ options:
type: str type: str
state: state:
description: description:
- Desired state of the resource. - Desired state of the resource. C(exists) will not modify the resource if it is present.
choices: ["present", "absent"] choices: ["present", "absent", "exists"]
default: "present" default: "present"
type: str type: str
@@ -216,7 +216,7 @@ def main():
update_secrets=dict(type='bool', default=True, no_log=False), update_secrets=dict(type='bool', default=True, no_log=False),
user=dict(), user=dict(),
team=dict(), team=dict(),
state=dict(choices=['present', 'absent'], default='present'), state=dict(choices=['present', 'absent', 'exists'], default='present'),
) )
# Create a module for ourselves # 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 # 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) 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) # Attempt to look up the related items the user specified (these will fail the module if not found)
if user: if user:
user_id = module.resolve_name_to_id('users', user) user_id = module.resolve_name_to_id('users', user)