diff --git a/plugins/modules/rds_option_group.py b/plugins/modules/rds_option_group.py index 118c08ea6ff..eeeb10ad48e 100644 --- a/plugins/modules/rds_option_group.py +++ b/plugins/modules/rds_option_group.py @@ -101,7 +101,7 @@ RETURN = r''' allows_vpc_and_non_vpc_instance_memberships: - description: Specifies the allocated storage size in gigabytes (GB). + description: Indicates whether this option group can be applied to both VPC and non-VPC instances. returned: I(state=present) type: bool sample: false @@ -109,8 +109,7 @@ description: If the Option Group has changed. type: bool returned: always - sample: - changed: true + sample: true engine_name: description: Indicates the name of the engine that this option group can be applied to. returned: I(state=present) @@ -142,13 +141,24 @@ type: complex contains: db_security_group_memberships: - description: Any VPCs attached to the internet gateway + description: If the option requires access to a port, then this DB security group allows access to the port. returned: I(state=present) type: complex sample: list elements: dict + contains: + status: + description: The status of the DB security group. + returned: I(state=present) + type: str + sample: "available" + db_security_group_name: + description: The name of the DB security group. + returned: I(state=present) + type: str + sample: "mydbsecuritygroup" option_description: - description: TThe description of the option. + description: The description of the option. returned: I(state=present) type: str sample: "Innodb Memcached for MySQL" @@ -223,7 +233,7 @@ type: int sample: 11211 vpc_security_group_memberships: - description: The name of the option. + description: If the option requires access to a port, then this VPC security group allows access to the port. returned: I(state=present) type: list elements: dict @@ -284,11 +294,11 @@ def create_option_group_options(client, module): params['ApplyImmediately'] = module.params.get('apply_immediately') try: - result = client.modify_option_group(aws_retry=True, **params) + client.modify_option_group(aws_retry=True, **params) except (botocore.exceptions.ClientError, botocore.exceptions.BotoCoreError) as e: module.fail_json_aws(e, msg="Unable to update Option Group.") - return changed, result + return changed def remove_option_group_options(client, module, options_to_remove): @@ -317,11 +327,11 @@ def create_option_group(client, module): params['OptionGroupDescription'] = module.params.get('option_group_description') try: - result = client.create_option_group(aws_retry=True, **params) + client.create_option_group(aws_retry=True, **params) except (botocore.exceptions.ClientError, botocore.exceptions.BotoCoreError) as e: module.fail_json_aws(e, msg='Unable to create Option Group.') - return changed, result + return changed def match_option_group_options(client, module): @@ -402,10 +412,10 @@ def setup_option_group(client, module): to_be_added, to_be_removed = compare_option_group(client, module) if to_be_added or update_required: - changed, new_option_group_options = create_option_group_options(client, module) + changed = create_option_group_options(client, module) if to_be_removed: - changed, removed_option_group_options = remove_option_group_options(client, module, to_be_removed) + changed = remove_option_group_options(client, module, to_be_removed) # If changed, get updated version of option group if changed: @@ -422,17 +432,17 @@ def setup_option_group(client, module): for option in current_option_group['Options']: options_to_remove.append(option['OptionName']) - changed, removed_option_group_options = remove_option_group_options(client, module, options_to_remove) + changed = remove_option_group_options(client, module, options_to_remove) # If changed, get updated version of option group if changed: results = get_option_group(client, module) else: - changed, new_option_group = create_option_group(client, module) + changed = create_option_group(client, module) if module.params.get('options'): - changed, new_option_group_options = create_option_group_options(client, module) + changed = create_option_group_options(client, module) results = get_option_group(client, module) @@ -459,19 +469,19 @@ def remove_option_group(client, module): def main(): argument_spec = dict( - option_group_name=dict(required=True, type=str), - engine_name=dict(type=str), - major_engine_version=dict(type=str), - option_group_description=dict(type=str), + option_group_name=dict(required=True, type='str'), + engine_name=dict(type='str'), + major_engine_version=dict(type='str'), + option_group_description=dict(type='str'), options=dict(type='list'), - apply_immediately=dict(type='bool'), + apply_immediately=dict(type='bool', default=False), state=dict(required=True, choices=['present', 'absent']), - required_if=[['state', 'present', ['engine_name', 'major_engine_version', 'option_group_description']]], ) module = AnsibleAWSModule( argument_spec=argument_spec, supports_check_mode=True, + required_if=[['state', 'present', ['engine_name', 'major_engine_version', 'option_group_description']]], ) try: diff --git a/plugins/modules/rds_option_group_info.py b/plugins/modules/rds_option_group_info.py index 82bc3ff8277..d22fbef0e28 100644 --- a/plugins/modules/rds_option_group_info.py +++ b/plugins/modules/rds_option_group_info.py @@ -16,17 +16,42 @@ requirements: [ boto3 ] author: "Alina Buzachis (@alinabuzachis)" options: - filters: - description: - - A dict of filters to apply. Each dict item consists of a filter key and a filter value. - See U(https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/rds.html#RDS.Client.describe_option_groups) for possible filters. - type: dict -.... - + option_group_name: + description: + - The name of the option group to describe. + - Can't be supplied together with EngineName or MajorEngineVersion. + type: str + required: true + filters: + description: + - A dict of filters to apply. Each dict item consists of a filter key and a filter value. + See U(https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/rds.html#RDS.Client.describe_option_groups) for possible filters. + type: dict + marker: + description: + - If this parameter is specified, the response includes only records beyond the marker, up to the value specified by MaxRecords. + - Constraints: Minimum 20, maximum 100. + type: str + required: false + max_records: + description: + - The maximum number of records to include in the response. + type: int + default: 100 + required: true + engine_name: + description: Filters the list of option groups to only include groups associated with a specific database engine. + type: str + required: false + major_engine_version: + description: + - Filters the list of option groups to only include groups associated with a specific database engine version. + - If specified, then EngineName must also be specified. + type: str + required: false extends_documentation_fragment: - amazon.aws.aws - amazon.aws.ec2 - ''' EXAMPLES = r''' @@ -42,7 +67,164 @@ ''' RETURN = r''' - +changed: + description: True if listing the internet gateways succeeds. + type: bool + returned: always + sample: "false" +option_groups_list: + description: The internet gateways for the account. + returned: always + type: complex + contains: + allows_vpc_and_non_vpc_instance_memberships: + description: Indicates whether this option group can be applied to both VPC and non-VPC instances. + returned: I(state=present) + type: bool + sample: false + engine_name: + description: Indicates the name of the engine that this option group can be applied to. + returned: I(state=present) + type: str + sample: "mysql" + major_engine_version: + description: Indicates the major engine version associated with this option group. + returned: I(state=present) + type: str + sample: "5.6" + option_group_arn: + description: The Amazon Resource Name (ARN) for the option group. + returned: I(state=present) + type: str + sample: "arn:aws:rds:ap-southeast-2:721066863947:og:ansible-test-option-group" + option_group_description: + description: Provides a description of the option group. + returned: I(state=present) + type: str + sample: "test mysql option group" + option_group_name: + description: Specifies the name of the option group. + returned: I(state=present) + type: str + sample: "test-mysql-option-group" + options: + description: Indicates what options are available in the option group. + returned: I(state=present) + type: complex + contains: + db_security_group_memberships: + description: If the option requires access to a port, then this DB security group allows access to the port. + returned: I(state=present) + type: complex + sample: list + elements: dict + contains: + status: + description: The status of the DB security group. + returned: I(state=present) + type: str + sample: "available" + db_security_group_name: + description: The name of the DB security group. + returned: I(state=present) + type: str + sample: "mydbsecuritygroup" + option_description: + description: The description of the option. + returned: I(state=present) + type: str + sample: "Innodb Memcached for MySQL" + option_name: + description: The name of the option. + returned: I(state=present) + type: str + sample: "MEMCACHED" + option_settings: + description: The name of the option. + returned: I(state=present) + type: complex + contains: + allowed_values: + description: The allowed values of the option setting. + returned: I(state=present) + type: str + sample: "1-2048" + apply_type: + description: The DB engine specific parameter type. + returned: I(state=present) + type: str + sample: "STATIC" + data_type: + description: The data type of the option setting. + returned: I(state=present) + type: str + sample: "INTEGER" + default_value: + description: The default value of the option setting. + returned: I(state=present) + type: str + sample: "1024" + description: + description: The description of the option setting. + returned: I(state=present) + type: str + sample: "Verbose level for memcached." + is_collection: + description: Indicates if the option setting is part of a collection. + returned: I(state=present) + type: bool + sample: true + is_modifiable: + description: A Boolean value that, when true, indicates the option setting can be modified from the default. + returned: I(state=present) + type: bool + sample: true + name: + description: The name of the option that has settings that you can set. + returned: I(state=present) + type: str + sample: "INNODB_API_ENABLE_MDL" + value: + description: The current value of the option setting. + returned: I(state=present) + type: str + sample: "0" + permanent: + description: Indicate if this option is permanent. + returned: I(state=present) + type: bool + sample: true + persistent: + description: Indicate if this option is persistent. + returned: I(state=present) + type: bool + sample: true + port: + description: If required, the port configured for this option to use. + returned: I(state=present) + type: int + sample: 11211 + vpc_security_group_memberships: + description: If the option requires access to a port, then this VPC security group allows access to the port. + returned: I(state=present) + type: list + elements: dict + contains: + status: + description: The status of the VPC security group. + returned: I(state=present) + type: str + sample: "available" + vpc_security_group_id: + description: The name of the VPC security group. + returned: I(state=present) + type: str + sample: "sg-0cd636a23ae76e9a4" + vpc_id: + description: If present, this option group can only be applied to instances that are in the VPC indicated by this field. + returned: I(state=present) + type: str + sample: "vpc-bf07e9d6" ''' try: @@ -62,6 +244,10 @@ def list_option_groups(client, module): params = dict() params['OptionGroupName'] = module.params.get('option_group_name') params['Filters'] = ansible_dict_to_boto3_filter_list(module.params.get('filters')) + params['Marker'] = module.params.get('marker') + params['MaxRecords'] = module.params.get('max_records') + params['EngineName'] = module.params.get('engine_name') + params['MajorEngineVersion'] = module.params.get('major_engine_version') try: result = client.describe_option_groups(aws_retry=True, **params) @@ -75,9 +261,23 @@ def main(): argument_spec = dict( option_group_name=dict(default='', type='str'), filters=dict(type='dict', default=dict()), + marker=dict(type='str', default=''), + max_records=dict(type=int, default=100), + engine_name=dict(type='str', default=''), + major_engine_version=dict(type='str', default=''), ) - module = AnsibleAWSModule(argument_spec=argument_spec, supports_check_mode=True) + module = AnsibleAWSModule( + argument_spec=argument_spec, + supports_check_mode=True, + mutually_exclusive=[ + ['option_group_name', 'engine_name'], + ['option_group_name', 'major_engine_version'], + ], + required_together=[ + ['engine_name', 'major_engine_version'], + ], + ) # Validate Requirements try: diff --git a/tests/integration/targets/rds_option_group/tasks/main.yml b/tests/integration/targets/rds_option_group/tasks/main.yml index b6ed93572ac..40077d6073f 100644 --- a/tests/integration/targets/rds_option_group/tasks/main.yml +++ b/tests/integration/targets/rds_option_group/tasks/main.yml @@ -120,6 +120,17 @@ - assert: that: - new_rds_mysql_option_group.changed + + - name: List specifig option group + rds_option_group_info: + <<: *creds + option_group_name: "{{ option_group_name }}" + register: option_groups_result + + - name: Assert success + assert: + that: + - option_groups_result is successful - name: Create an RDS Mysql option group (idempotency) rds_option_group: @@ -145,6 +156,18 @@ - assert: that: - not new_rds_mysql_option_group.changed + + - name: List option groups with specific (engine_name and major_engine_version) + rds_option_group_info: + <<: *creds + engine_name: "{{ engine_name }}" + major_engine_version: "{{ major_engine_version }}" + register: option_groups_result + + - name: Assert success + assert: + that: + - option_groups_result is successful - name: Create an RDS Mysql option group - apply different changes (expected changed=true) rds_option_group: