Debian Codegraph @

ansible_collections/amazon/aws/plugins/modules/rds_option_group_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: rds_option_group_info
10 short_description: rds_option_group_info module
11 version_added: 5.0.0
12 description:
13 - Gather information about RDS option groups.
14 - This module was originally added to C(community.aws) in release 2.1.0.
15 author: "Alina Buzachis (@alinabuzachis)"
16 options:
17 option_group_name:
18 description:
19 - The name of the option group to describe.
20 - Can't be supplied together with O(engine_name) or O(major_engine_version).
21 default: ''
22 required: false
23 type: str
24 marker:
25 description:
26 - If this parameter is specified, the response includes only records beyond the marker, up to the value specified by O(max_records).
27 - Allowed values are between V(20) and V(100).
28 required: false
29 type: str
30 max_records:
31 description:
32 - The maximum number of records to include in the response.
33 type: int
34 default: 100
35 required: false
36 engine_name:
37 description: Filters the list of option groups to only include groups associated with a specific database engine.
38 type: str
39 default: ''
40 required: false
41 major_engine_version:
42 description:
43 - Filters the list of option groups to only include groups associated with a specific database engine version.
44 - If specified, then O(engine_name) must also be specified.
45 type: str
46 default: ''
47 required: false
48 extends_documentation_fragment:
49 - amazon.aws.common.modules
50 - amazon.aws.region.modules
51 - amazon.aws.boto3
52 """
53
54 EXAMPLES = r"""
55 # Note: These examples do not set authentication details, see the AWS Guide for details.
56
57 - name: List an option group
58 amazon.aws.rds_option_group_info:
59 option_group_name: test-mysql-option-group
60 register: option_group
61
62 - name: List all the option groups
63 amazon.aws.rds_option_group_info:
64 region: ap-southeast-2
65 profile: production
66 register: option_group
67 """
68
69 RETURN = r"""
70 changed:
71 description: True if listing the RDS option group succeeds.
72 type: bool
73 returned: always
74 sample: false
75 result:
76 description: The available RDS option groups.
77 returned: always
78 type: complex
79 contains:
80 allows_vpc_and_non_vpc_instance_memberships:
81 description: Indicates whether this option group can be applied to both VPC and non-VPC instances.
82 returned: always
83 type: bool
84 sample: false
85 engine_name:
86 description: Indicates the name of the engine that this option group can be applied to.
87 returned: always
88 type: str
89 sample: "mysql"
90 major_engine_version:
91 description: Indicates the major engine version associated with this option group.
92 returned: always
93 type: str
94 sample: "5.6"
95 option_group_arn:
96 description: The Amazon Resource Name (ARN) for the option group.
97 returned: always
98 type: str
99 sample: "arn:aws:rds:ap-southeast-2:123456789012:og:ansible-test-option-group"
100 option_group_description:
101 description: Provides a description of the option group.
102 returned: always
103 type: str
104 sample: "test mysql option group"
105 option_group_name:
106 description: Specifies the name of the option group.
107 returned: always
108 type: str
109 sample: "test-mysql-option-group"
110 options:
111 description: Indicates what options are available in the option group.
112 returned: always
113 type: complex
114 contains:
115 db_security_group_memberships:
116 description: If the option requires access to a port, then this DB security group allows access to the port.
117 returned: always
118 type: complex
119 sample: list
120 elements: dict
121 contains:
122 status:
123 description: The status of the DB security group.
124 returned: always
125 type: str
126 sample: "available"
127 db_security_group_name:
128 description: The name of the DB security group.
129 returned: always
130 type: str
131 sample: "mydbsecuritygroup"
132 option_description:
133 description: The description of the option.
134 returned: always
135 type: str
136 sample: "Innodb Memcached for MySQL"
137 option_name:
138 description: The name of the option.
139 returned: always
140 type: str
141 sample: "MEMCACHED"
142 option_settings:
143 description: The name of the option.
144 returned: always
145 type: complex
146 contains:
147 allowed_values:
148 description: The allowed values of the option setting.
149 returned: always
150 type: str
151 sample: "1-2048"
152 apply_type:
153 description: The DB engine specific parameter type.
154 returned: always
155 type: str
156 sample: "STATIC"
157 data_type:
158 description: The data type of the option setting.
159 returned: always
160 type: str
161 sample: "INTEGER"
162 default_value:
163 description: The default value of the option setting.
164 returned: always
165 type: str
166 sample: "1024"
167 description:
168 description: The description of the option setting.
169 returned: always
170 type: str
171 sample: "Verbose level for memcached."
172 is_collection:
173 description: Indicates if the option setting is part of a collection.
174 returned: always
175 type: bool
176 sample: true
177 is_modifiable:
178 description: A Boolean value that, when true, indicates the option setting can be modified from the default.
179 returned: always
180 type: bool
181 sample: true
182 name:
183 description: The name of the option that has settings that you can set.
184 returned: always
185 type: str
186 sample: "INNODB_API_ENABLE_MDL"
187 value:
188 description: The current value of the option setting.
189 returned: always
190 type: str
191 sample: "0"
192 permanent:
193 description: Indicate if this option is permanent.
194 returned: always
195 type: bool
196 sample: true
197 persistent:
198 description: Indicate if this option is persistent.
199 returned: always
200 type: bool
201 sample: true
202 port:
203 description: If required, the port configured for this option to use.
204 returned: always
205 type: int
206 sample: 11211
207 vpc_security_group_memberships:
208 description: If the option requires access to a port, then this VPC security group allows access to the port.
209 returned: always
210 type: list
211 elements: dict
212 contains:
213 status:
214 description: The status of the VPC security group.
215 returned: always
216 type: str
217 sample: "available"
218 vpc_security_group_id:
219 description: The name of the VPC security group.
220 returned: always
221 type: str
222 sample: "sg-0cd636a23ae76e9a4"
223 vpc_id:
224 description: If present, this option group can only be applied to instances that are in the VPC indicated by this field.
225 returned: always
226 type: str
227 sample: "vpc-bf07e9d6"
228 tags:
229 description: The tags associated the RDS option group.
230 type: dict
231 returned: always
232 sample: {
233 "Ansible": "Test"
234 }
235
236 """
237
238 try:
239 import botocore
240 except ImportError:
241 pass # Handled by AnsibleAWSModule
242
243 from ansible.module_utils.common.dict_transformations import camel_dict_to_snake_dict
244
245 from ansible_collections.amazon.aws.plugins.module_utils.botocore import is_boto3_error_code
246 from ansible_collections.amazon.aws.plugins.module_utils.modules import AnsibleAWSModule
247 from ansible_collections.amazon.aws.plugins.module_utils.rds import get_tags
248 from ansible_collections.amazon.aws.plugins.module_utils.retries import AWSRetry
249
250
251 @AWSRetry.jittered_backoff(retries=10)
252 def _describe_option_groups(client, **params):
253 try:
254 paginator = client.get_paginator("describe_option_groups")
255 return paginator.paginate(**params).build_full_result()
256 except is_boto3_error_code("OptionGroupNotFoundFault"):
257 return {}
258
259
260 def list_option_groups(client, module):
261 option_groups = list()
262 params = dict()
263 params["OptionGroupName"] = module.params.get("option_group_name")
264
265 if module.params.get("marker"):
266 params["Marker"] = module.params.get("marker")
267 if int(params["Marker"]) < 20 or int(params["Marker"]) > 100:
268 module.fail_json(msg="marker must be between 20 and 100 minutes")
269
270 if module.params.get("max_records"):
271 params["MaxRecords"] = module.params.get("max_records")
272 if params["MaxRecords"] > 100:
273 module.fail_json(msg="The maximum number of records to include in the response is 100.")
274
275 params["EngineName"] = module.params.get("engine_name")
276 params["MajorEngineVersion"] = module.params.get("major_engine_version")
277
278 try:
279 result = _describe_option_groups(client, **params)
280 except (botocore.exceptions.ClientError, botocore.exceptions.BotoCoreError) as e:
281 module.fail_json_aws(e, msg="Couldn't describe option groups.")
282
283 for option_group in result["OptionGroupsList"]:
284 # Turn the boto3 result into ansible_friendly_snaked_names
285 converted_option_group = camel_dict_to_snake_dict(option_group)
286 converted_option_group["tags"] = get_tags(client, module, converted_option_group["option_group_arn"])
287 option_groups.append(converted_option_group)
288
289 return option_groups
290
291
292 def main():
293 argument_spec = dict(
294 option_group_name=dict(default="", type="str"),
295 marker=dict(type="str"),
296 max_records=dict(type="int", default=100),
297 engine_name=dict(type="str", default=""),
298 major_engine_version=dict(type="str", default=""),
299 )
300
301 module = AnsibleAWSModule(
302 argument_spec=argument_spec,
303 supports_check_mode=True,
304 mutually_exclusive=[
305 ["option_group_name", "engine_name"],
306 ["option_group_name", "major_engine_version"],
307 ],
308 required_together=[
309 ["engine_name", "major_engine_version"],
310 ],
311 )
312
313 # Validate Requirements
314 try:
315 connection = module.client("rds", retry_decorator=AWSRetry.jittered_backoff())
316 except (botocore.exceptions.ClientError, botocore.exceptions.BotoCoreError) as e:
317 module.fail_json_aws(e, msg="Failed to connect to AWS")
318
319 results = list_option_groups(connection, module)
320
321 module.exit_json(result=results)
322
323
324 if __name__ == "__main__":
325 main()