| 1 |
#!/usr/bin/python |
| 2 |
# -*- coding: utf-8 -*- |
| 3 |
|
| 4 |
# Copyright (c) 2023 Ansible Project |
| 5 |
# Copyright (c) 2023 Gomathi Selvi Srinivasan (@GomathiselviS) |
| 6 |
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) |
| 7 |
|
| 8 |
DOCUMENTATION = r""" |
| 9 |
module: rds_global_cluster_info |
| 10 |
version_added: 7.0.0 |
| 11 |
short_description: Obtain information about Aurora global database clusters |
| 12 |
description: |
| 13 |
- Obtain information about Aurora global database clusters. |
| 14 |
options: |
| 15 |
global_cluster_identifier: |
| 16 |
description: |
| 17 |
- The user-supplied Global DB cluster identifier. |
| 18 |
- If this parameter is specified, information from only the specific DB cluster is returned. |
| 19 |
- This parameter is not case-sensitive. |
| 20 |
- If supplied, must match an existing DBClusterIdentifier. |
| 21 |
type: str |
| 22 |
|
| 23 |
author: |
| 24 |
- Gomathi Selvi Srinivasan (@GomathiselviS) |
| 25 |
notes: |
| 26 |
- While developing this module, describe_global_cluster CLI did not yield any tag information. |
| 27 |
- Consequently, the "tags" parameter is not included in this module. |
| 28 |
extends_documentation_fragment: |
| 29 |
- amazon.aws.common.modules |
| 30 |
- amazon.aws.region.modules |
| 31 |
- amazon.aws.boto3 |
| 32 |
""" |
| 33 |
|
| 34 |
EXAMPLES = r""" |
| 35 |
- name: Get info of all existing DB clusters |
| 36 |
amazon.aws.rds_global_cluster_info: |
| 37 |
register: _result_cluster_info |
| 38 |
|
| 39 |
- name: Get info on a specific DB cluster |
| 40 |
amazon.aws.rds_global_cluster_info: |
| 41 |
global_cluster_identifier: "{{ cluster_id }}" |
| 42 |
register: _result_global_cluster_info |
| 43 |
""" |
| 44 |
|
| 45 |
RETURN = r""" |
| 46 |
global_clusters: |
| 47 |
description: List of global clusters. |
| 48 |
returned: always |
| 49 |
type: list |
| 50 |
elements: dict |
| 51 |
contains: |
| 52 |
global_cluster_identifier: |
| 53 |
description: User-supplied global database cluster identifier. |
| 54 |
type: str |
| 55 |
sample: "ansible-test-global-cluster" |
| 56 |
global_cluster_resource_id: |
| 57 |
description: |
| 58 |
- The Amazon Web Services Region-unique, immutable identifier for the global database cluster. |
| 59 |
type: str |
| 60 |
returned: always |
| 61 |
sample: "cluster-123456789012" |
| 62 |
global_cluster_arn: |
| 63 |
description: |
| 64 |
- The Amazon Resource Name (ARN) for the global database cluster. |
| 65 |
type: str |
| 66 |
returned: always |
| 67 |
sample: "arn:aws:rds::123456789012:global-cluster:ansible-test-global-cluster" |
| 68 |
status: |
| 69 |
description: The status of the DB cluster. |
| 70 |
type: str |
| 71 |
returned: always |
| 72 |
sample: "available" |
| 73 |
engine: |
| 74 |
description: The database engine of the DB cluster. |
| 75 |
type: str |
| 76 |
returned: always |
| 77 |
sample: "aurora-postgresql" |
| 78 |
engine_version: |
| 79 |
description: The database engine version. |
| 80 |
type: str |
| 81 |
returned: always |
| 82 |
sample: "14.8" |
| 83 |
storage_encrypted: |
| 84 |
description: Whether the DB cluster is storage encrypted. |
| 85 |
type: bool |
| 86 |
returned: always |
| 87 |
sample: false |
| 88 |
deletion_protection: |
| 89 |
description: |
| 90 |
- Indicates if the DB cluster has deletion protection enabled. |
| 91 |
The database can't be deleted when deletion protection is enabled. |
| 92 |
type: bool |
| 93 |
returned: always |
| 94 |
sample: false |
| 95 |
gloabl_cluster_members: |
| 96 |
description: |
| 97 |
- The list of primary and secondary clusters within the global database |
| 98 |
cluster. |
| 99 |
type: list |
| 100 |
elements: dict |
| 101 |
contains: |
| 102 |
db_cluster_arn: |
| 103 |
description: The Amazon Resource Name (ARN) for each Aurora DB cluster in the global cluster. |
| 104 |
type: str |
| 105 |
returned: always |
| 106 |
sample: "arn:aws:rds:us-east-1:123456789012:cluster:ansible-test-primary" |
| 107 |
readers: |
| 108 |
description: The Amazon Resource Name (ARN) for each read-only secondary cluster associated with the global cluster. |
| 109 |
type: list |
| 110 |
elements: str |
| 111 |
returned: always |
| 112 |
sample: "arn:aws:rds:us-east-2:123456789012:cluster:ansible-test-secondary" |
| 113 |
is_writer: |
| 114 |
description: |
| 115 |
- Indicates whether the Aurora DB cluster is the primary cluster for the global cluster with which it is associated. |
| 116 |
returned: always |
| 117 |
type: bool |
| 118 |
sample: false |
| 119 |
global_write_forwarding_status: |
| 120 |
description: The status of write forwarding for a secondary cluster in the global cluster. |
| 121 |
type: str |
| 122 |
returned: always |
| 123 |
sample: disabled |
| 124 |
failover_state: |
| 125 |
description: |
| 126 |
- A data object containing all properties for the current state of an in-process or |
| 127 |
pending switchover or failover process for this global cluster (Aurora global database). |
| 128 |
- This object is empty unless the SwitchoverGlobalCluster or FailoverGlobalCluster operation was called on this global cluster. |
| 129 |
type: dict |
| 130 |
contains: |
| 131 |
status: |
| 132 |
description: |
| 133 |
- The current status of the global cluster. |
| 134 |
type: str |
| 135 |
returned: always |
| 136 |
sample: "pending" |
| 137 |
from_db_cluster_arn: |
| 138 |
description: The Amazon Resource Name (ARN) of the Aurora DB cluster that is currently being demoted, and which is associated with this state. |
| 139 |
type: str |
| 140 |
returned: always |
| 141 |
sample: "arn:aws:rds:us-east-1:123456789012:cluster:ansible-test-primary" |
| 142 |
to_db_cluster_arn: |
| 143 |
description: The Amazon Resource Name (ARN) of the Aurora DB cluster that is currently being promoted, and which is associated with this state. |
| 144 |
type: str |
| 145 |
returned: always |
| 146 |
sample: "arn:aws:rds:us-east-2:123456789012:cluster:ansible-test-secondary" |
| 147 |
is_data_loss_allowed: |
| 148 |
description: |
| 149 |
- Indicates whether the operation is a global switchover or a global failover. |
| 150 |
- If data loss is allowed, then the operation is a global failover. Otherwise, it is a switchover. |
| 151 |
type: bool |
| 152 |
returned: always |
| 153 |
sample: false |
| 154 |
""" |
| 155 |
|
| 156 |
|
| 157 |
try: |
| 158 |
import botocore |
| 159 |
except ImportError: |
| 160 |
pass # handled by AnsibleAWSModule |
| 161 |
|
| 162 |
from ansible.module_utils.common.dict_transformations import camel_dict_to_snake_dict |
| 163 |
|
| 164 |
from ansible_collections.amazon.aws.plugins.module_utils.botocore import is_boto3_error_code |
| 165 |
from ansible_collections.amazon.aws.plugins.module_utils.modules import AnsibleAWSModule |
| 166 |
from ansible_collections.amazon.aws.plugins.module_utils.retries import AWSRetry |
| 167 |
|
| 168 |
|
| 169 |
@AWSRetry.jittered_backoff(retries=10) |
| 170 |
def _describe_global_clusters(client, **params): |
| 171 |
try: |
| 172 |
paginator = client.get_paginator("describe_global_clusters") |
| 173 |
return paginator.paginate(**params).build_full_result()["GlobalClusters"] |
| 174 |
except is_boto3_error_code("GlobalClusterNotFoundFault"): |
| 175 |
return [] |
| 176 |
|
| 177 |
|
| 178 |
def cluster_info(client, module): |
| 179 |
global_cluster_id = module.params.get("global_cluster_identifier") |
| 180 |
|
| 181 |
params = dict() |
| 182 |
if global_cluster_id: |
| 183 |
params["GlobalClusterIdentifier"] = global_cluster_id |
| 184 |
|
| 185 |
try: |
| 186 |
result = _describe_global_clusters(client, **params) |
| 187 |
except (botocore.exceptions.ClientError, botocore.exceptions.BotoCoreError) as e: |
| 188 |
module.fail_json_aws(e, "Couldn't get Global cluster information.") |
| 189 |
|
| 190 |
return dict( |
| 191 |
changed=False, global_clusters=[camel_dict_to_snake_dict(cluster, ignore_list=["Tags"]) for cluster in result] |
| 192 |
) |
| 193 |
|
| 194 |
|
| 195 |
def main(): |
| 196 |
argument_spec = dict( |
| 197 |
global_cluster_identifier=dict(), |
| 198 |
) |
| 199 |
|
| 200 |
module = AnsibleAWSModule( |
| 201 |
argument_spec=argument_spec, |
| 202 |
supports_check_mode=True, |
| 203 |
) |
| 204 |
|
| 205 |
try: |
| 206 |
client = module.client("rds", retry_decorator=AWSRetry.jittered_backoff(retries=10)) |
| 207 |
except (botocore.exceptions.ClientError, botocore.exceptions.BotoCoreError) as e: |
| 208 |
module.fail_json_aws(e, msg="Failed to connect to AWS.") |
| 209 |
|
| 210 |
module.exit_json(**cluster_info(client, module)) |
| 211 |
|
| 212 |
|
| 213 |
if __name__ == "__main__": |
| 214 |
main() |