|  | 
|  | 1 | +#!/usr/bin/env python | 
|  | 2 | +# -*- coding: utf-8 -*- | 
|  | 3 | + | 
|  | 4 | +# Copyright 2021 Cloudera, Inc. All Rights Reserved. | 
|  | 5 | +# | 
|  | 6 | +# Licensed under the Apache License, Version 2.0 (the "License"); | 
|  | 7 | +# you may not use this file except in compliance with the License. | 
|  | 8 | +# You may obtain a copy of the License at | 
|  | 9 | +# | 
|  | 10 | +#      http://www.apache.org/licenses/LICENSE-2.0 | 
|  | 11 | +# | 
|  | 12 | +# Unless required by applicable law or agreed to in writing, software | 
|  | 13 | +# distributed under the License is distributed on an "AS IS" BASIS, | 
|  | 14 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 
|  | 15 | +# See the License for the specific language governing permissions and | 
|  | 16 | +# limitations under the License. | 
|  | 17 | + | 
|  | 18 | +from ansible.module_utils.basic import AnsibleModule | 
|  | 19 | +from ansible_collections.cloudera.cloud.plugins.module_utils.cdp_common import CdpModule | 
|  | 20 | + | 
|  | 21 | +ANSIBLE_METADATA = {'metadata_version': '1.1', | 
|  | 22 | +                    'status': ['preview'], | 
|  | 23 | +                    'supported_by': 'community'} | 
|  | 24 | + | 
|  | 25 | +DOCUMENTATION = ''' | 
|  | 26 | +--- | 
|  | 27 | +module: env_automated_user_sync_info | 
|  | 28 | +short_description: Get the status of the automated CDP Users and Groups synchronization service | 
|  | 29 | +description: | 
|  | 30 | +  - Get the status of the automated synchronization for users and groups for a given Environment. | 
|  | 31 | +  - Requires the C(WORKLOAD_IAM_SYNC) entitlement. | 
|  | 32 | +  - The module support check_mode. | 
|  | 33 | +author: | 
|  | 34 | +  - "Webster Mudge (@wmudge)" | 
|  | 35 | +requirements: | 
|  | 36 | +  - cdpy | 
|  | 37 | +options: | 
|  | 38 | +  name: | 
|  | 39 | +    description: | 
|  | 40 | +      - The CDP Environment name or CRN to check. | 
|  | 41 | +    aliases: | 
|  | 42 | +      - environment | 
|  | 43 | +    required: True | 
|  | 44 | +    type: str | 
|  | 45 | +extends_documentation_fragment: | 
|  | 46 | +  - cloudera.cloud.cdp_sdk_options | 
|  | 47 | +  - cloudera.cloud.cdp_auth_options | 
|  | 48 | +''' | 
|  | 49 | + | 
|  | 50 | +EXAMPLES = r''' | 
|  | 51 | +# Note: These examples do not set authentication details. | 
|  | 52 | +
 | 
|  | 53 | +# Get the status of a sync event (non-WORKLOAD_IAM_SYNC) | 
|  | 54 | +- cloudera.cloud.env_automated_user_sync_info: | 
|  | 55 | +    name: example-env | 
|  | 56 | +''' | 
|  | 57 | + | 
|  | 58 | +RETURN = r''' | 
|  | 59 | +sync: | 
|  | 60 | +    description: Returns an object describing of the status of the automated User and Group synchronization service. | 
|  | 61 | +    returned: success | 
|  | 62 | +    type: complex | 
|  | 63 | +    contains: | 
|  | 64 | +        environmentCrn: | 
|  | 65 | +            description: The environment CRN. | 
|  | 66 | +            returned: always | 
|  | 67 | +            type: str | 
|  | 68 | +        lastSyncStatus: | 
|  | 69 | +            description: Status of the last automated sync operation for the environment. | 
|  | 70 | +            returned: always | 
|  | 71 | +            type: dict | 
|  | 72 | +            contains: | 
|  | 73 | +                status: | 
|  | 74 | +                    description: The status of the sync. | 
|  | 75 | +                    returned: always | 
|  | 76 | +                    type: str | 
|  | 77 | +                    sample: | 
|  | 78 | +                        - UNKNOWN | 
|  | 79 | +                        - SUCCESS | 
|  | 80 | +                        - FAILED | 
|  | 81 | +                statusMessages: | 
|  | 82 | +                    description: Additional detail related to the status. | 
|  | 83 | +                    returned: when supported | 
|  | 84 | +                    type: list | 
|  | 85 | +                    elements: str | 
|  | 86 | +                timestamp: | 
|  | 87 | +                    description: A datetime stamp of when the sync was processed. | 
|  | 88 | +                    returned: always | 
|  | 89 | +                    type: str | 
|  | 90 | +        syncPendingState: | 
|  | 91 | +            description: The state indicating whether the environment is synced or has a sync pending. | 
|  | 92 | +            returned: always | 
|  | 93 | +            type: str | 
|  | 94 | +            sample: | 
|  | 95 | +                - UNKNOWN | 
|  | 96 | +                - SYNC_PENDING | 
|  | 97 | +                - SYNCED | 
|  | 98 | +                - SYNC_HALTED | 
|  | 99 | +sdk_out: | 
|  | 100 | +    description: Returns the captured CDP SDK log. | 
|  | 101 | +    returned: when supported | 
|  | 102 | +    type: str | 
|  | 103 | +sdk_out_lines: | 
|  | 104 | +    description: Returns a list of each line of the captured CDP SDK log. | 
|  | 105 | +    returned: when supported | 
|  | 106 | +    type: list | 
|  | 107 | +    elements: str | 
|  | 108 | +''' | 
|  | 109 | + | 
|  | 110 | + | 
|  | 111 | +class EnvironmentAutomatedUserSyncInfo(CdpModule): | 
|  | 112 | +    def __init__(self, module): | 
|  | 113 | +        super(EnvironmentAutomatedUserSyncInfo, self).__init__(module) | 
|  | 114 | + | 
|  | 115 | +        # Set variables | 
|  | 116 | +        self.name = self.module.params['name'] | 
|  | 117 | + | 
|  | 118 | +        # Initialize the return values | 
|  | 119 | +        self.sync = {} | 
|  | 120 | +        self.changed = False | 
|  | 121 | + | 
|  | 122 | +        # Execute logic process | 
|  | 123 | +        self.process() | 
|  | 124 | + | 
|  | 125 | +    @CdpModule._Decorators.process_debug | 
|  | 126 | +    def process(self): | 
|  | 127 | +        self.sync = self.cdpy.environments.get_automated_sync_environment_status(self.name) | 
|  | 128 | + | 
|  | 129 | + | 
|  | 130 | +def main(): | 
|  | 131 | +    module = AnsibleModule( | 
|  | 132 | +        argument_spec=CdpModule.argument_spec( | 
|  | 133 | +            name=dict(required=True, type='str', aliases=['environment']) | 
|  | 134 | +        ), | 
|  | 135 | +        supports_check_mode=True | 
|  | 136 | +    ) | 
|  | 137 | + | 
|  | 138 | +    result = EnvironmentAutomatedUserSyncInfo(module) | 
|  | 139 | + | 
|  | 140 | +    output = dict( | 
|  | 141 | +        changed=result.changed, | 
|  | 142 | +        sync=result.sync, | 
|  | 143 | +    ) | 
|  | 144 | + | 
|  | 145 | +    if result.debug: | 
|  | 146 | +        output.update( | 
|  | 147 | +            sdk_out=result.log_out, | 
|  | 148 | +            sdk_out_lines=result.log_lines | 
|  | 149 | +        ) | 
|  | 150 | + | 
|  | 151 | +    module.exit_json(**output) | 
|  | 152 | + | 
|  | 153 | + | 
|  | 154 | +if __name__ == '__main__': | 
|  | 155 | +    main() | 
0 commit comments