diff --git a/docsrc/index.rst b/docsrc/index.rst index 86ee7feb..ef172ecc 100644 --- a/docsrc/index.rst +++ b/docsrc/index.rst @@ -35,6 +35,7 @@ cloudera.cloud Ansible Collection env env_auth env_auth_info + env_automated_user_sync_info env_cred env_cred_info env_idbroker diff --git a/plugins/README.md b/plugins/README.md index 026e8a45..7a5fffdd 100644 --- a/plugins/README.md +++ b/plugins/README.md @@ -37,6 +37,7 @@ modules employ the underlying SDK contained within the `cdpy` Python package. | [env](./modules/env.py) | Create, manage, and destroy CDP Environments | | [env_auth](./modules/env_auth.py) | Set authentication details for CDP Environments | | [env_auth_info](./modules/env_auth_info.py) | Gather information about CDP Environment authentication details | +| [env_automated_user_sync_info](./modules/env_automated_user_sync_info.py) | Get the status of the automated CDP Users and Groups synchronization service | | [env_cred](./modules/env_cred.py) | Create, update, and destroy CDP Credentials | | [env_cred_info](./modules/env_cred_info.py) | Gather information about CDP Credentials | | [env_idbroker](./modules/env_idbroker.py) | Manage CDP Environment ID Broker data access mappings | diff --git a/plugins/modules/env_automated_user_sync_info.py b/plugins/modules/env_automated_user_sync_info.py new file mode 100644 index 00000000..08df332b --- /dev/null +++ b/plugins/modules/env_automated_user_sync_info.py @@ -0,0 +1,155 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +# Copyright 2022 Cloudera, Inc. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +from ansible.module_utils.basic import AnsibleModule +from ansible_collections.cloudera.cloud.plugins.module_utils.cdp_common import CdpModule + +ANSIBLE_METADATA = {'metadata_version': '1.1', + 'status': ['preview'], + 'supported_by': 'community'} + +DOCUMENTATION = ''' +--- +module: env_automated_user_sync_info +short_description: Get the status of the automated CDP Users and Groups synchronization service +description: + - Get the status of the automated synchronization for users and groups for a given Environment. + - Requires the C(WORKLOAD_IAM_SYNC) entitlement. + - The module support check_mode. +author: + - "Webster Mudge (@wmudge)" +requirements: + - cdpy +options: + name: + description: + - The CDP Environment name or CRN to check. + aliases: + - environment + required: True + type: str +extends_documentation_fragment: + - cloudera.cloud.cdp_sdk_options + - cloudera.cloud.cdp_auth_options +''' + +EXAMPLES = r''' +# Note: These examples do not set authentication details. + +# Get the status of a sync event (non-WORKLOAD_IAM_SYNC) +- cloudera.cloud.env_automated_user_sync_info: + name: example-env +''' + +RETURN = r''' +sync: + description: Returns an object describing of the status of the automated User and Group synchronization service. + returned: success + type: complex + contains: + environmentCrn: + description: The environment CRN. + returned: always + type: str + lastSyncStatus: + description: Status of the last automated sync operation for the environment. + returned: always + type: dict + contains: + status: + description: The status of the sync. + returned: always + type: str + sample: + - UNKNOWN + - SUCCESS + - FAILED + statusMessages: + description: Additional detail related to the status. + returned: when supported + type: list + elements: str + timestamp: + description: A datetime stamp of when the sync was processed. + returned: always + type: str + syncPendingState: + description: The state indicating whether the environment is synced or has a sync pending. + returned: always + type: str + sample: + - UNKNOWN + - SYNC_PENDING + - SYNCED + - SYNC_HALTED +sdk_out: + description: Returns the captured CDP SDK log. + returned: when supported + type: str +sdk_out_lines: + description: Returns a list of each line of the captured CDP SDK log. + returned: when supported + type: list + elements: str +''' + + +class EnvironmentAutomatedUserSyncInfo(CdpModule): + def __init__(self, module): + super(EnvironmentAutomatedUserSyncInfo, self).__init__(module) + + # Set variables + self.name = self.module.params['name'] + + # Initialize the return values + self.sync = {} + self.changed = False + + # Execute logic process + self.process() + + @CdpModule._Decorators.process_debug + def process(self): + self.sync = self.cdpy.environments.get_automated_sync_environment_status(self.name) + + +def main(): + module = AnsibleModule( + argument_spec=CdpModule.argument_spec( + name=dict(required=True, type='str', aliases=['environment']) + ), + supports_check_mode=True + ) + + result = EnvironmentAutomatedUserSyncInfo(module) + + output = dict( + changed=result.changed, + sync=result.sync, + ) + + if result.debug: + output.update( + sdk_out=result.log_out, + sdk_out_lines=result.log_lines + ) + + module.exit_json(**output) + + +if __name__ == '__main__': + main() diff --git a/plugins/modules/env_user_sync_info.py b/plugins/modules/env_user_sync_info.py index e134f00e..9bfd7565 100644 --- a/plugins/modules/env_user_sync_info.py +++ b/plugins/modules/env_user_sync_info.py @@ -37,9 +37,10 @@ options: name: description: - - The C(operations id) for a User and Group sync event. + - The C(operations id) for a User and Group sync event or the C(operations CRN) for the event if the C(WORKLOAD_IAM_SYNC) entitlement is enabled aliases: - operations_id + - operations_crn required: True type: str extends_documentation_fragment: @@ -50,7 +51,7 @@ EXAMPLES = r''' # Note: These examples do not set authentication details. -# Get the status of a sync event +# Get the status of a sync event (non-WORKLOAD_IAM_SYNC) - cloudera.cloud.env_user_sync_info: name: 0e9bc67a-b308-4275-935c-b8c764dc13be ''' @@ -85,7 +86,7 @@ returned: when supported type: str operationId: - description: UUID of the request for this operation. + description: UUID (or CRN, if running with the C(WORKLOAD_IAM_SYNC) entitlement) of the request for this operation. returned: always type: str sample: 0e9bc67a-b308-4275-935c-b8c764dc13be @@ -159,7 +160,7 @@ def process(self): def main(): module = AnsibleModule( argument_spec=CdpModule.argument_spec( - name=dict(required=True, type='str', aliases=['operation_id']) + name=dict(required=True, type='str', aliases=['operation_id', 'operation_crn']) ), supports_check_mode=True )