Debian Codegraph @

ansible_collections/community/aws/plugins/modules/opensearch_info.py

raw
1 #!/usr/bin/python
2 # -*- coding: utf-8 -*-
3
4 # Copyright: Ansible Project
5 # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
6
7 DOCUMENTATION = r"""
8 ---
9 module: opensearch_info
10 short_description: obtain information about one or more OpenSearch or ElasticSearch domain
11 description:
12 - Obtain information about one Amazon OpenSearch Service domain.
13 version_added: 4.0.0
14 author:
15 - "Sebastien Rosset (@sebastien-rosset)"
16 options:
17 domain_name:
18 description:
19 - The name of the Amazon OpenSearch/ElasticSearch Service domain.
20 required: false
21 type: str
22 tags:
23 description:
24 - >
25 A dict of tags that are used to filter OpenSearch domains that match
26 all tag key, value pairs.
27 required: false
28 type: dict
29 extends_documentation_fragment:
30 - amazon.aws.common.modules
31 - amazon.aws.region.modules
32 - amazon.aws.boto3
33 """
34
35 EXAMPLES = r"""
36 - name: Get information about an OpenSearch domain instance
37 community.aws.opensearch_info:
38 domain_name: my-search-cluster
39 register: new_cluster_info
40
41 - name: Get all OpenSearch instances
42 community.aws.opensearch_info:
43
44 - name: Get all OpenSearch instances that have the specified Key, Value tags
45 community.aws.opensearch_info:
46 tags:
47 Applications: search
48 Environment: Development
49 """
50
51 RETURN = r"""
52 instances:
53 description: List of OpenSearch domain instances
54 returned: always
55 type: complex
56 contains:
57 domain_status:
58 description: The current status of the OpenSearch domain.
59 returned: always
60 type: complex
61 contains:
62 arn:
63 description: The ARN of the OpenSearch domain.
64 returned: always
65 type: str
66 domain_id:
67 description: The unique identifier for the OpenSearch domain.
68 returned: always
69 type: str
70 domain_name:
71 description: The name of the OpenSearch domain.
72 returned: always
73 type: str
74 created:
75 description:
76 - >
77 The domain creation status. True if the creation of a domain is complete.
78 False if domain creation is still in progress.
79 returned: always
80 type: bool
81 deleted:
82 description:
83 - >
84 The domain deletion status.
85 True if a delete request has been received for the domain but resource cleanup is still in progress.
86 False if the domain has not been deleted.
87 Once domain deletion is complete, the status of the domain is no longer returned.
88 returned: always
89 type: bool
90 endpoint:
91 description: The domain endpoint that you use to submit index and search requests.
92 returned: always
93 type: str
94 endpoints:
95 description:
96 - >
97 Map containing the domain endpoints used to submit index and search requests.
98 - >
99 When you create a domain attached to a VPC domain, this propery contains
100 the DNS endpoint to which service requests are submitted.
101 - >
102 If you query the opensearch_info immediately after creating the OpenSearch cluster,
103 the VPC endpoint may not be returned. It may take several minutes until the
104 endpoints is available.
105 type: dict
106 processing:
107 description:
108 - >
109 The status of the domain configuration.
110 True if Amazon OpenSearch Service is processing configuration changes.
111 False if the configuration is active.
112 returned: always
113 type: bool
114 upgrade_processing:
115 description: true if a domain upgrade operation is in progress.
116 returned: always
117 type: bool
118 engine_version:
119 description: The version of the OpenSearch domain.
120 returned: always
121 type: str
122 sample: OpenSearch_1.1
123 cluster_config:
124 description:
125 - Parameters for the cluster configuration of an OpenSearch Service domain.
126 type: complex
127 contains:
128 instance_type:
129 description:
130 - Type of the instances to use for the domain.
131 type: str
132 instance_count:
133 description:
134 - Number of instances for the domain.
135 type: int
136 zone_awareness:
137 description:
138 - A boolean value to indicate whether zone awareness is enabled.
139 type: bool
140 availability_zone_count:
141 description:
142 - >
143 An integer value to indicate the number of availability zones for a domain when zone awareness is enabled.
144 This should be equal to number of subnets if VPC endpoints is enabled.
145 type: int
146 dedicated_master_enabled:
147 description:
148 - A boolean value to indicate whether a dedicated master node is enabled.
149 type: bool
150 zone_awareness_enabled:
151 description:
152 - A boolean value to indicate whether zone awareness is enabled.
153 type: bool
154 zone_awareness_config:
155 description:
156 - The zone awareness configuration for a domain when zone awareness is enabled.
157 type: complex
158 contains:
159 availability_zone_count:
160 description:
161 - An integer value to indicate the number of availability zones for a domain when zone awareness is enabled.
162 type: int
163 dedicated_master_type:
164 description:
165 - The instance type for a dedicated master node.
166 type: str
167 dedicated_master_count:
168 description:
169 - Total number of dedicated master nodes, active and on standby, for the domain.
170 type: int
171 warm_enabled:
172 description:
173 - True to enable UltraWarm storage.
174 type: bool
175 warm_type:
176 description:
177 - The instance type for the OpenSearch domain's warm nodes.
178 type: str
179 warm_count:
180 description:
181 - The number of UltraWarm nodes in the domain.
182 type: int
183 cold_storage_options:
184 description:
185 - Specifies the ColdStorageOptions config for a Domain.
186 type: complex
187 contains:
188 enabled:
189 description:
190 - True to enable cold storage. Supported on Elasticsearch 7.9 or above.
191 type: bool
192 ebs_options:
193 description:
194 - Parameters to configure EBS-based storage for an OpenSearch Service domain.
195 type: complex
196 contains:
197 ebs_enabled:
198 description:
199 - Specifies whether EBS-based storage is enabled.
200 type: bool
201 volume_type:
202 description:
203 - Specifies the volume type for EBS-based storage. "standard"|"gp2"|"io1"
204 type: str
205 volume_size:
206 description:
207 - Integer to specify the size of an EBS volume.
208 type: int
209 iops:
210 description:
211 - The IOPD for a Provisioned IOPS EBS volume (SSD).
212 type: int
213 vpc_options:
214 description:
215 - Options to specify the subnets and security groups for a VPC endpoint.
216 type: complex
217 contains:
218 vpc_id:
219 description: The VPC ID for the domain.
220 type: str
221 subnet_ids:
222 description:
223 - Specifies the subnet ids for VPC endpoint.
224 type: list
225 elements: str
226 security_group_ids:
227 description:
228 - Specifies the security group ids for VPC endpoint.
229 type: list
230 elements: str
231 availability_zones:
232 description:
233 - The Availability Zones for the domain..
234 type: list
235 elements: str
236 snapshot_options:
237 description:
238 - Option to set time, in UTC format, of the daily automated snapshot.
239 type: complex
240 contains:
241 automated_snapshot_start_hour:
242 description:
243 - >
244 Integer value from 0 to 23 specifying when the service takes a daily automated snapshot
245 of the specified Elasticsearch domain.
246 type: int
247 access_policies:
248 description:
249 - IAM access policy as a JSON-formatted string.
250 type: complex
251 encryption_at_rest_options:
252 description:
253 - Parameters to enable encryption at rest.
254 type: complex
255 contains:
256 enabled:
257 description:
258 - Should data be encrypted while at rest.
259 type: bool
260 kms_key_id:
261 description:
262 - If encryption at rest enabled, this identifies the encryption key to use.
263 - The value should be a KMS key ARN. It can also be the KMS key id.
264 type: str
265 node_to_node_encryption_options:
266 description:
267 - Node-to-node encryption options.
268 type: complex
269 contains:
270 enabled:
271 description:
272 - True to enable node-to-node encryption.
273 type: bool
274 cognito_options:
275 description:
276 - Parameters to configure OpenSearch Service to use Amazon Cognito authentication for OpenSearch Dashboards.
277 type: complex
278 contains:
279 enabled:
280 description:
281 - The option to enable Cognito for OpenSearch Dashboards authentication.
282 type: bool
283 user_pool_id:
284 description:
285 - The Cognito user pool ID for OpenSearch Dashboards authentication.
286 type: str
287 identity_pool_id:
288 description:
289 - The Cognito identity pool ID for OpenSearch Dashboards authentication.
290 type: str
291 role_arn:
292 description:
293 - The role ARN that provides OpenSearch permissions for accessing Cognito resources.
294 type: str
295 domain_endpoint_options:
296 description:
297 - Options to specify configuration that will be applied to the domain endpoint.
298 type: complex
299 contains:
300 enforce_https:
301 description:
302 - Whether only HTTPS endpoint should be enabled for the domain.
303 type: bool
304 tls_security_policy:
305 description:
306 - Specify the TLS security policy to apply to the HTTPS endpoint of the domain.
307 type: str
308 custom_endpoint_enabled:
309 description:
310 - Whether to enable a custom endpoint for the domain.
311 type: bool
312 custom_endpoint:
313 description:
314 - The fully qualified domain for your custom endpoint.
315 type: str
316 custom_endpoint_certificate_arn:
317 description:
318 - The ACM certificate ARN for your custom endpoint.
319 type: str
320 advanced_security_options:
321 description:
322 - Specifies advanced security options.
323 type: complex
324 contains:
325 enabled:
326 description:
327 - True if advanced security is enabled.
328 - You must enable node-to-node encryption to use advanced security options.
329 type: bool
330 internal_user_database_enabled:
331 description:
332 - True if the internal user database is enabled.
333 type: bool
334 master_user_options:
335 description:
336 - Credentials for the master user, username and password, ARN, or both.
337 type: complex
338 contains:
339 master_user_arn:
340 description:
341 - ARN for the master user (if IAM is enabled).
342 type: str
343 master_user_name:
344 description:
345 - The username of the master user, which is stored in the Amazon OpenSearch Service domain internal database.
346 type: str
347 master_user_password:
348 description:
349 - The password of the master user, which is stored in the Amazon OpenSearch Service domain internal database.
350 type: str
351 saml_options:
352 description:
353 - The SAML application configuration for the domain.
354 type: complex
355 contains:
356 enabled:
357 description:
358 - True if SAML is enabled.
359 type: bool
360 idp:
361 description:
362 - The SAML Identity Provider's information.
363 type: complex
364 contains:
365 metadata_content:
366 description:
367 - The metadata of the SAML application in XML format.
368 type: str
369 entity_id:
370 description:
371 - The unique entity ID of the application in SAML identity provider.
372 type: str
373 master_user_name:
374 description:
375 - The SAML master username, which is stored in the Amazon OpenSearch Service domain internal database.
376 type: str
377 master_backend_role:
378 description:
379 - The backend role that the SAML master user is mapped to.
380 type: str
381 subject_key:
382 description:
383 - Element of the SAML assertion to use for username. Default is NameID.
384 type: str
385 roles_key:
386 description:
387 - Element of the SAML assertion to use for backend roles. Default is roles.
388 type: str
389 session_timeout_minutes:
390 description:
391 - >
392 The duration, in minutes, after which a user session becomes inactive.
393 Acceptable values are between 1 and 1440, and the default value is 60.
394 type: int
395 auto_tune_options:
396 description:
397 - Specifies Auto-Tune options.
398 type: complex
399 contains:
400 desired_state:
401 description:
402 - The Auto-Tune desired state. Valid values are ENABLED and DISABLED.
403 type: str
404 maintenance_schedules:
405 description:
406 - A list of maintenance schedules.
407 type: list
408 elements: dict
409 contains:
410 start_at:
411 description:
412 - The timestamp at which the Auto-Tune maintenance schedule starts.
413 type: str
414 duration:
415 description:
416 - Specifies maintenance schedule duration, duration value and duration unit.
417 type: complex
418 contains:
419 value:
420 description:
421 - Integer to specify the value of a maintenance schedule duration.
422 type: int
423 unit:
424 description:
425 - The unit of a maintenance schedule duration. Valid value is HOURS.
426 type: str
427 cron_expression_for_recurrence:
428 description:
429 - A cron expression for a recurring maintenance schedule.
430 type: str
431 domain_config:
432 description: The OpenSearch domain configuration
433 returned: always
434 type: complex
435 contains:
436 domain_name:
437 description: The name of the OpenSearch domain.
438 returned: always
439 type: str
440 """
441
442
443 try:
444 import botocore
445 except ImportError:
446 pass # handled by AnsibleAWSModule
447
448 from ansible.module_utils.common.dict_transformations import camel_dict_to_snake_dict
449
450 from ansible_collections.amazon.aws.plugins.module_utils.retries import AWSRetry
451 from ansible_collections.amazon.aws.plugins.module_utils.tagging import boto3_tag_list_to_ansible_dict
452
453 from ansible_collections.community.aws.plugins.module_utils.modules import AnsibleCommunityAWSModule as AnsibleAWSModule
454 from ansible_collections.community.aws.plugins.module_utils.opensearch import get_domain_config
455 from ansible_collections.community.aws.plugins.module_utils.opensearch import get_domain_status
456
457
458 def domain_info(client, module):
459 domain_name = module.params.get("domain_name")
460 filter_tags = module.params.get("tags")
461
462 domain_list = []
463 if domain_name:
464 domain_status = get_domain_status(client, module, domain_name)
465 if domain_status:
466 domain_list.append({"DomainStatus": domain_status})
467 else:
468 domain_summary_list = client.list_domain_names()["DomainNames"]
469 for d in domain_summary_list:
470 domain_status = get_domain_status(client, module, d["DomainName"])
471 if domain_status:
472 domain_list.append({"DomainStatus": domain_status})
473
474 # Get the domain tags
475 for domain in domain_list:
476 current_domain_tags = None
477 domain_arn = domain["DomainStatus"]["ARN"]
478 try:
479 current_domain_tags = client.list_tags(ARN=domain_arn, aws_retry=True)["TagList"]
480 domain["Tags"] = boto3_tag_list_to_ansible_dict(current_domain_tags)
481 except (botocore.exceptions.ClientError, botocore.exceptions.BotoCoreError):
482 # This could potentially happen if a domain is deleted between the time
483 # its domain status was queried and the tags were queried.
484 domain["Tags"] = {}
485
486 # Filter by tags
487 if filter_tags:
488 for tag_key in filter_tags:
489 try:
490 domain_list = [
491 c
492 for c in domain_list
493 if ("Tags" in c) and (tag_key in c["Tags"]) and (c["Tags"][tag_key] == filter_tags[tag_key])
494 ]
495 except (TypeError, AttributeError) as e:
496 module.fail_json(msg="OpenSearch tag filtering error", exception=e)
497
498 # Get the domain config
499 for idx, domain in enumerate(domain_list):
500 domain_name = domain["DomainStatus"]["DomainName"]
501 (domain_config, arn) = get_domain_config(client, module, domain_name)
502 if domain_config:
503 domain["DomainConfig"] = domain_config
504 domain_list[idx] = camel_dict_to_snake_dict(domain, ignore_list=["AdvancedOptions", "Endpoints", "Tags"])
505
506 return dict(changed=False, domains=domain_list)
507
508
509 def main():
510 module = AnsibleAWSModule(
511 argument_spec=dict(
512 domain_name=dict(required=False),
513 tags=dict(type="dict", required=False),
514 ),
515 supports_check_mode=True,
516 )
517
518 try:
519 client = module.client("opensearch", retry_decorator=AWSRetry.jittered_backoff())
520 except (botocore.exceptions.ClientError, botocore.exceptions.BotoCoreError) as e:
521 module.fail_json_aws(e, msg="Failed to connect to AWS opensearch service")
522
523 module.exit_json(**domain_info(client, module))
524
525
526 if __name__ == "__main__":
527 main()