Пример #1
0
def main():
    argument_spec = dict(log_group_name=dict(), )

    module = AnsibleAWSModule(argument_spec=argument_spec,
                              supports_check_mode=True)
    if module._name == 'cloudwatchlogs_log_group_facts':
        module.deprecate(
            "The 'cloudwatchlogs_log_group_facts' module has been renamed to 'cloudwatchlogs_log_group_info'",
            date='2021-12-01',
            collection_name='community.aws')

    region, ec2_url, aws_connect_kwargs = get_aws_connection_info(module,
                                                                  boto3=True)
    logs = boto3_conn(module,
                      conn_type='client',
                      resource='logs',
                      region=region,
                      endpoint=ec2_url,
                      **aws_connect_kwargs)

    desc_log_group = describe_log_group(
        client=logs,
        log_group_name=module.params['log_group_name'],
        module=module)
    final_log_group_snake = []

    for log_group in desc_log_group['logGroups']:
        final_log_group_snake.append(camel_dict_to_snake_dict(log_group))

    desc_log_group_result = dict(changed=False,
                                 log_groups=final_log_group_snake)
    module.exit_json(**desc_log_group_result)
Пример #2
0
def main():
    argument_spec = dict(
        names={'default': [], 'type': 'list', 'elements': 'str'}
    )
    module = AnsibleAWSModule(argument_spec=argument_spec,
                              supports_check_mode=True)

    if module._name == 'ec2_elb_facts':
        # The ec2_elb_facts alias was already deprecated
        module.deprecate("The 'ec2_elb_facts' module has been deprecated and replaced by the 'elb_classic_lb_info' module'",
                         version='3.0.0', collection_name='community.aws')
    if module._name == 'ec2_elb_info':
        module.deprecate("The 'ec2_elb_info' module has been deprecated and replaced by the 'elb_classic_lb_info' module'",
                         version='3.0.0', collection_name='community.aws')

    if not HAS_BOTO:
        module.fail_json(msg='boto required for this module')

    try:
        region, ec2_url, aws_connect_params = get_aws_connection_info(module)
        if not region:
            module.fail_json(msg="region must be specified")

        names = module.params['names']
        elb_information = ElbInformation(
            module, names, region, **aws_connect_params)

        ec2_info_result = dict(changed=False,
                               elbs=elb_information.list_elbs())

    except BotoServerError as err:
        module.fail_json(msg="{0}: {1}".format(err.error_code, err.error_message),
                         exception=traceback.format_exc())

    module.exit_json(**ec2_info_result)
Пример #3
0
def main():

    argument_spec = dict(
        details=dict(type='bool', default=False),
        events=dict(type='bool', default=True),
        cluster=dict(),
        service=dict(type='list', elements='str')
    )

    module = AnsibleAWSModule(argument_spec=argument_spec, supports_check_mode=True)
    is_old_facts = module._name == 'ecs_service_facts'
    if is_old_facts:
        module.deprecate("The 'ecs_service_facts' module has been renamed to 'ecs_service_info', "
                         "and the renamed one no longer returns ansible_facts", date='2021-12-01', collection_name='community.aws')

    show_details = module.params.get('details')

    task_mgr = EcsServiceManager(module)
    if show_details:
        if module.params['service']:
            services = module.params['service']
        else:
            services = task_mgr.list_services(module.params['cluster'])['services']
        ecs_info = dict(services=[], services_not_running=[])
        for chunk in chunks(services, 10):
            running_services, services_not_running = task_mgr.describe_services(module.params['cluster'], chunk)
            ecs_info['services'].extend(running_services)
            ecs_info['services_not_running'].extend(services_not_running)
    else:
        ecs_info = task_mgr.list_services(module.params['cluster'])

    if is_old_facts:
        module.exit_json(changed=False, ansible_facts=ecs_info, **ecs_info)
    else:
        module.exit_json(changed=False, **ecs_info)
def main():
    argument_spec = dict(
        db_snapshot_identifier=dict(aliases=['snapshot_name']),
        db_instance_identifier=dict(),
        db_cluster_identifier=dict(),
        db_cluster_snapshot_identifier=dict(),
        snapshot_type=dict(
            choices=['automated', 'manual', 'shared', 'public']))

    module = AnsibleAWSModule(argument_spec=argument_spec,
                              supports_check_mode=True,
                              mutually_exclusive=[[
                                  'db_snapshot_identifier',
                                  'db_instance_identifier',
                                  'db_cluster_identifier',
                                  'db_cluster_snapshot_identifier'
                              ]])
    if module._name == 'rds_snapshot_facts':
        module.deprecate(
            "The 'rds_snapshot_facts' module has been renamed to 'rds_snapshot_info'",
            date='2021-12-01',
            collection_name='community.aws')

    conn = module.client('rds',
                         retry_decorator=AWSRetry.jittered_backoff(retries=10))
    results = dict()
    if not module.params['db_cluster_identifier'] and not module.params[
            'db_cluster_snapshot_identifier']:
        results['snapshots'] = standalone_snapshot_info(module, conn)
    if not module.params['db_snapshot_identifier'] and not module.params[
            'db_instance_identifier']:
        results['cluster_snapshots'] = cluster_snapshot_info(module, conn)

    module.exit_json(changed=False, **results)
def main():
    argument_spec = dict(
        filters=dict(type='dict', default=dict()),
        internet_gateway_ids=dict(type='list', default=None, elements='str'),
    )

    module = AnsibleAWSModule(argument_spec=argument_spec,
                              supports_check_mode=True)
    if module._name == 'ec2_vpc_igw_facts':
        module.deprecate(
            "The 'ec2_vpc_igw_facts' module has been renamed to 'ec2_vpc_igw_info'",
            date='2021-12-01',
            collection_name='community.aws')

    # Validate Requirements
    try:
        region, ec2_url, aws_connect_kwargs = get_aws_connection_info(
            module, boto3=True)
        connection = boto3_conn(module,
                                conn_type='client',
                                resource='ec2',
                                region=region,
                                endpoint=ec2_url,
                                **aws_connect_kwargs)
    except botocore.exceptions.NoCredentialsError as e:
        module.fail_json(msg="Can't authorize connection - " + str(e))

    # call your function here
    results = list_internet_gateways(connection, module)

    module.exit_json(internet_gateways=results)
Пример #6
0
def main():
    argument_spec = dict(
        filters=dict(default=dict(), type='dict'),
        peer_connection_ids=dict(default=None, type='list', elements='str'),
    )

    module = AnsibleAWSModule(
        argument_spec=argument_spec,
        supports_check_mode=True,
    )
    if module._name == 'ec2_vpc_peering_facts':
        module.deprecate(
            "The 'ec2_vpc_peering_facts' module has been renamed to 'ec2_vpc_peering_info'",
            date='2021-12-01',
            collection_name='community.aws')

    try:
        ec2 = module.client('ec2')
    except (botocore.exceptions.ClientError,
            botocore.exceptions.BotoCoreError) as e:
        module.fail_json_aws(e, msg='Failed to connect to AWS')

    # Turn the boto3 result in to ansible friendly_snaked_names
    results = [
        camel_dict_to_snake_dict(peer) for peer in get_vpc_peers(ec2, module)
    ]

    # Turn the boto3 result in to ansible friendly tag dictionary
    for peer in results:
        peer['tags'] = boto3_tag_list_to_ansible_dict(peer.get('tags', []))

    module.exit_json(result=results)
Пример #7
0
def main():

    argument_spec = dict(instance_ids=dict(default=[],
                                           type='list',
                                           elements='str'),
                         filters=dict(default={}, type='dict'))

    module = AnsibleAWSModule(
        argument_spec=argument_spec,
        mutually_exclusive=[['instance_ids', 'filters']],
        supports_check_mode=True,
    )
    if module._name == 'ec2_instance_facts':
        module.deprecate(
            "The 'ec2_instance_facts' module has been renamed to 'ec2_instance_info'",
            date='2021-12-01',
            collection_name='community.aws')

    region, ec2_url, aws_connect_params = get_aws_connection_info(module,
                                                                  boto3=True)

    if region:
        connection = boto3_conn(module,
                                conn_type='client',
                                resource='ec2',
                                region=region,
                                endpoint=ec2_url,
                                **aws_connect_params)
    else:
        module.fail_json(msg="region must be specified")

    list_ec2_instances(connection, module)
Пример #8
0
def main():

    argument_spec = dict(
        load_balancer_arn=dict(type='str'),
        target_group_arns=dict(type='list', elements='str'),
        names=dict(type='list', elements='str'),
        collect_targets_health=dict(default=False, type='bool',
                                    required=False),
    )

    module = AnsibleAWSModule(
        argument_spec=argument_spec,
        mutually_exclusive=[[
            'load_balancer_arn', 'target_group_arns', 'names'
        ]],
        supports_check_mode=True,
    )
    if module._name == 'elb_target_group_facts':
        module.deprecate(
            "The 'elb_target_group_facts' module has been renamed to 'elb_target_group_info'",
            date='2021-12-01',
            collection_name='community.aws')

    try:
        connection = module.client('elbv2')
    except (botocore.exceptions.ClientError,
            botocore.exceptions.BotoCoreError) as e:
        module.fail_json_aws(e, msg='Failed to connect to AWS')

    list_target_groups(connection, module)
Пример #9
0
def main():
    argument_spec = dict(
        filters=dict(type='dict'),
        pending_deletion=dict(type='bool', default=False),
    )

    module = AnsibleAWSModule(argument_spec=argument_spec,
                              supports_check_mode=True)
    if module._name == 'aws_kms_facts':
        module.deprecate(
            "The 'aws_kms_facts' module has been renamed to 'aws_kms_info'",
            date='2021-12-01',
            collection_name='community.aws')

    try:
        connection = module.client('kms')
    except (botocore.exceptions.ClientError,
            botocore.exceptions.BotoCoreError) as e:
        module.fail_json_aws(e, msg='Failed to connect to AWS')

    all_keys = get_kms_info(connection, module)
    module.exit_json(keys=[
        key for key in all_keys
        if key_matches_filters(key, module.params['filters'])
    ])
Пример #10
0
def main():
    argument_spec = dict(
        certificate_arn=dict(aliases=['arn']),
        domain_name=dict(aliases=['name']),
        statuses=dict(type='list', choices=['PENDING_VALIDATION', 'ISSUED', 'INACTIVE', 'EXPIRED', 'VALIDATION_TIMED_OUT', 'REVOKED', 'FAILED']),
        tags=dict(type='dict'),
    )
    module = AnsibleAWSModule(argument_spec=argument_spec, supports_check_mode=True)
    acm_info = ACMServiceManager(module)

    if module._name == 'aws_acm_facts':
        module.deprecate("The 'aws_acm_facts' module has been renamed to 'aws_acm_info'", date='2021-12-01', collection_name='community.aws')

    client = module.client('acm')

    certificates = acm_info.get_certificates(client, module,
                                             domain_name=module.params['domain_name'],
                                             statuses=module.params['statuses'],
                                             arn=module.params['certificate_arn'],
                                             only_tags=module.params['tags'])

    if module.params['certificate_arn'] and len(certificates) != 1:
        module.fail_json(msg="No certificate exists in this region with ARN %s" % module.params['certificate_arn'])

    module.exit_json(certificates=certificates)
Пример #11
0
def main():
    argument_spec = dict(
        query=dict(choices=['services', 'endpoints'], required=True),
        filters=dict(default={}, type='dict'),
        vpc_endpoint_ids=dict(type='list', elements='str'),
    )

    module = AnsibleAWSModule(argument_spec=argument_spec,
                              supports_check_mode=True)
    if module._name == 'ec2_vpc_endpoint_facts':
        module.deprecate(
            "The 'ec2_vpc_endpoint_facts' module has been renamed to 'ec2_vpc_endpoint_info'",
            date='2021-12-01',
            collection_name='community.aws')

    # Validate Requirements
    try:
        connection = module.client('ec2')
    except (botocore.exceptions.ClientError,
            botocore.exceptions.BotoCoreError) as e:
        module.fail_json_aws(e, msg='Failed to connect to AWS')

    invocations = {
        'services': get_supported_services,
        'endpoints': get_endpoints,
    }
    results = invocations[module.params.get('query')](connection, module)

    module.exit_json(**results)
def main():
    argument_spec = dict(filters=dict(default=None, type='dict'), )

    module = AnsibleAWSModule(argument_spec=argument_spec,
                              supports_check_mode=True)
    if module._name == 'ec2_vpc_route_table_facts':
        module.deprecate(
            "The 'ec2_vpc_route_table_facts' module has been renamed to 'ec2_vpc_route_table_info'",
            date='2021-12-01',
            collection_name='community.aws')

    if not HAS_BOTO:
        module.fail_json(msg='boto required for this module')

    region, ec2_url, aws_connect_params = get_aws_connection_info(module)

    if region:
        try:
            connection = connect_to_aws(boto.vpc, region, **aws_connect_params)
        except (boto.exception.NoAuthHandlerFound, AnsibleAWSError) as e:
            module.fail_json(msg=str(e))
    else:
        module.fail_json(msg="region must be specified")

    list_ec2_vpc_route_tables(connection, module)
Пример #13
0
def main():
    argument_spec = dict(
        filters=dict(type='dict', default=dict()),
        internet_gateway_ids=dict(type='list', default=None, elements='str'),
        convert_tags=dict(type='bool'),
    )

    module = AnsibleAWSModule(argument_spec=argument_spec,
                              supports_check_mode=True)
    if module._name == 'ec2_vpc_igw_facts':
        module.deprecate(
            "The 'ec2_vpc_igw_facts' module has been renamed to 'ec2_vpc_igw_info'",
            date='2021-12-01',
            collection_name='community.aws')

    if module.params.get('convert_tags') is None:
        module.deprecate(
            'This module currently returns boto3 style tags by default.  '
            'This default has been deprecated and the module will return a simple dictionary in future.  '
            'This behaviour can be controlled through the convert_tags parameter.',
            date='2021-12-01',
            collection_name='community.aws')

    # Validate Requirements
    try:
        connection = module.client('ec2',
                                   retry_decorator=AWSRetry.jittered_backoff())
    except (botocore.exceptions.ClientError,
            botocore.exceptions.BotoCoreError) as e:
        module.fail_json_aws(e, msg='Failed to connect to AWS')

    # call your function here
    results = list_internet_gateways(connection, module)

    module.exit_json(internet_gateways=results)
Пример #14
0
def main():
    argument_spec = dict(
        filters=dict(default={}, type='dict'),
        nat_gateway_ids=dict(default=[], type='list', elements='str'),
    )

    module = AnsibleAWSModule(
        argument_spec=argument_spec,
        supports_check_mode=True,
    )
    if module._name == 'ec2_vpc_nat_gateway_facts':
        module.deprecate(
            "The 'ec2_vpc_nat_gateway_facts' module has been renamed to 'ec2_vpc_nat_gateway_info'",
            date='2021-12-01',
            collection_name='community.aws')

    try:
        connection = module.client('ec2',
                                   retry_decorator=AWSRetry.jittered_backoff())
    except (botocore.exceptions.ClientError,
            botocore.exceptions.BotoCoreError) as e:
        module.fail_json_aws(e, msg='Failed to connect to AWS')

    results = get_nat_gateways(connection, module)

    module.exit_json(result=results)
def main():
    """
    Get list of S3 buckets
    :return:
    """

    # Ensure we have an empty dict
    result = {}

    # Including ec2 argument spec
    module = AnsibleAWSModule(argument_spec={}, supports_check_mode=True)
    is_old_facts = module._name == 'aws_s3_bucket_facts'
    if is_old_facts:
        module.deprecate(
            "The 'aws_s3_bucket_facts' module has been renamed to 'aws_s3_bucket_info', "
            "and the renamed one no longer returns ansible_facts",
            date='2021-12-01',
            collection_name='community.aws')

    # Set up connection
    try:
        connection = module.client('s3')
    except (botocore.exceptions.ClientError,
            botocore.exceptions.BotoCoreError) as e:
        module.fail_json_aws(e, msg='Failed to connect to AWS')

    # Gather results
    result['buckets'] = get_bucket_list(module, connection)

    # Send exit
    if is_old_facts:
        module.exit_json(msg="Retrieved s3 facts.", ansible_facts=result)
    else:
        module.exit_json(msg="Retrieved s3 info.", **result)
Пример #16
0
def main():

    argument_spec = dict(minimum_uptime=dict(required=False,
                                             type='int',
                                             default=None,
                                             aliases=['uptime']),
                         instance_ids=dict(default=[],
                                           type='list',
                                           elements='str'),
                         filters=dict(default={}, type='dict'))

    module = AnsibleAWSModule(
        argument_spec=argument_spec,
        mutually_exclusive=[['instance_ids', 'filters']],
        supports_check_mode=True,
    )
    if module._name == 'ec2_instance_facts':
        module.deprecate(
            "The 'ec2_instance_facts' module has been renamed to 'ec2_instance_info'",
            date='2021-12-01',
            collection_name='community.aws')

    try:
        connection = module.client('ec2')
    except (botocore.exceptions.ClientError,
            botocore.exceptions.BotoCoreError) as e:
        module.fail_json_aws(e, msg='Failed to connect to AWS')

    list_ec2_instances(connection, module)
Пример #17
0
def main():

    argument_spec = dict(
        name=dict(type='str'),
        tags=dict(type='dict'),
    )

    module = AnsibleAWSModule(
        argument_spec=argument_spec,
        supports_check_mode=True,
    )

    if module._name == 'ec2_asg_facts':
        module.deprecate(
            "The 'ec2_asg_facts' module has been renamed to 'ec2_asg_info'",
            date='2021-12-01',
            collection_name='community.aws')

    asg_name = module.params.get('name')
    asg_tags = module.params.get('tags')

    autoscaling = module.client('autoscaling')

    results = find_asgs(autoscaling, module, name=asg_name, tags=asg_tags)
    module.exit_json(results=results)
Пример #18
0
def main():
    argument_spec = dict(
        filters=dict(type='dict'),
        pending_deletion=dict(type='bool', default=False),
    )

    module = AnsibleAWSModule(argument_spec=argument_spec,
                              supports_check_mode=True)
    if module._name == 'aws_kms_facts':
        module.deprecate(
            "The 'aws_kms_facts' module has been renamed to 'aws_kms_info'",
            date='2021-12-01',
            collection_name='community.aws')

    region, ec2_url, aws_connect_params = get_aws_connection_info(module,
                                                                  boto3=True)

    if region:
        connection = boto3_conn(module,
                                conn_type='client',
                                resource='kms',
                                region=region,
                                endpoint=ec2_url,
                                **aws_connect_params)
    else:
        module.fail_json(msg="region must be specified")

    all_keys = get_kms_info(connection, module)
    module.exit_json(keys=[
        key for key in all_keys
        if key_matches_filters(key, module.params['filters'])
    ])
Пример #19
0
def main():
    argument_spec = dict(
        name=dict(required=False, default=[], type='list', elements='str'),
        sort=dict(required=False,
                  default=None,
                  choices=[
                      'launch_configuration_name', 'image_id', 'created_time',
                      'instance_type', 'kernel_id', 'ramdisk_id', 'key_name'
                  ]),
        sort_order=dict(required=False,
                        default='ascending',
                        choices=['ascending', 'descending']),
        sort_start=dict(required=False, type='int'),
        sort_end=dict(required=False, type='int'),
    )

    module = AnsibleAWSModule(
        argument_spec=argument_spec,
        supports_check_mode=True,
    )

    if module._name == 'ec2_lc_facts':
        module.deprecate(
            "The 'ec2_lc_facts' module has been renamed to 'ec2_lc_info'",
            date='2021-12-01',
            collection_name='community.aws')

    try:
        connection = module.client('autoscaling')
    except (botocore.exceptions.ClientError,
            botocore.exceptions.BotoCoreError) as e:
        module.fail_json_aws(e, msg='Failed to connect to AWS')

    list_launch_configs(connection, module)
def main():
    argument_spec = dict(
        filters=dict(default={}, type='dict'),
        nat_gateway_ids=dict(default=[], type='list', elements='str'),
    )

    module = AnsibleAWSModule(
        argument_spec=argument_spec,
        supports_check_mode=True,
    )
    if module._name == 'ec2_vpc_nat_gateway_facts':
        module.deprecate(
            "The 'ec2_vpc_nat_gateway_facts' module has been renamed to 'ec2_vpc_nat_gateway_info'",
            date='2021-12-01',
            collection_name='community.aws')

    try:
        region, ec2_url, aws_connect_params = get_aws_connection_info(
            module, boto3=True)
        if region:
            connection = boto3_conn(module,
                                    conn_type='client',
                                    resource='ec2',
                                    region=region,
                                    endpoint=ec2_url,
                                    **aws_connect_params)
        else:
            module.fail_json(msg="region must be specified")
    except botocore.exceptions.NoCredentialsError as e:
        module.fail_json(msg=str(e))

    results = get_nat_gateways(connection, module)

    module.exit_json(result=results)
Пример #21
0
def main():

    argument_spec = dict(load_balancer_arns=dict(type='list', elements='str'),
                         names=dict(type='list', elements='str'))

    module = AnsibleAWSModule(
        argument_spec=argument_spec,
        mutually_exclusive=[['load_balancer_arns', 'names']],
        supports_check_mode=True,
    )
    if module._name == 'elb_application_lb_facts':
        module.deprecate(
            "The 'elb_application_lb_facts' module has been renamed to 'elb_application_lb_info'",
            date='2021-12-01',
            collection_name='community.aws')

    region, ec2_url, aws_connect_params = get_aws_connection_info(module,
                                                                  boto3=True)

    if region:
        connection = boto3_conn(module,
                                conn_type='client',
                                resource='elbv2',
                                region=region,
                                endpoint=ec2_url,
                                **aws_connect_params)
    else:
        module.fail_json(msg="region must be specified")

    list_load_balancers(connection, module)
Пример #22
0
def main():
    argument_spec = dict(instance_id={
        "required": True,
        "type": "str"
    },
                         get_unused_target_groups={
                             "required": False,
                             "default": True,
                             "type": "bool"
                         })

    module = AnsibleAWSModule(
        argument_spec=argument_spec,
        supports_check_mode=True,
    )
    if module._name == 'elb_target_facts':
        module.deprecate(
            "The 'elb_target_facts' module has been renamed to 'elb_target_info'",
            date='2021-12-01',
            collection_name='community.aws')

    instance_id = module.params["instance_id"]
    get_unused_target_groups = module.params["get_unused_target_groups"]

    tg_gatherer = TargetInfoGatherer(module, instance_id,
                                     get_unused_target_groups)

    instance_target_groups = [each.to_dict() for each in tg_gatherer.tgs]

    module.exit_json(instance_target_groups=instance_target_groups)
Пример #23
0
def main():
    argument_spec = dict(filters=dict(default={}, type='dict'))

    module = AnsibleAWSModule(argument_spec=argument_spec,
                              supports_check_mode=True)
    if module._name == 'aws_region_facts':
        module.deprecate(
            "The 'aws_region_facts' module has been renamed to 'aws_region_info'",
            date='2021-12-01',
            collection_name='community.aws')

    connection = module.client('ec2',
                               retry_decorator=AWSRetry.jittered_backoff())

    # Replace filter key underscores with dashes, for compatibility
    sanitized_filters = dict(module.params.get('filters'))
    for k in module.params.get('filters').keys():
        if "_" in k:
            sanitized_filters[k.replace('_', '-')] = sanitized_filters[k]
            del sanitized_filters[k]

    try:
        regions = connection.describe_regions(
            aws_retry=True,
            Filters=ansible_dict_to_boto3_filter_list(sanitized_filters))
    except (BotoCoreError, ClientError) as e:
        module.fail_json_aws(e, msg="Unable to describe regions.")

    module.exit_json(
        regions=[camel_dict_to_snake_dict(r) for r in regions['Regions']])
Пример #24
0
def main():
    argument_spec = dict(log_group_name=dict(), )

    module = AnsibleAWSModule(argument_spec=argument_spec,
                              supports_check_mode=True)
    if module._name == 'cloudwatchlogs_log_group_facts':
        module.deprecate(
            "The 'cloudwatchlogs_log_group_facts' module has been renamed to 'cloudwatchlogs_log_group_info'",
            date='2021-12-01',
            collection_name='community.aws')

    try:
        logs = module.client('logs')
    except (botocore.exceptions.ClientError,
            botocore.exceptions.BotoCoreError) as e:
        module.fail_json_aws(e, msg='Failed to connect to AWS')

    desc_log_group = describe_log_group(
        client=logs,
        log_group_name=module.params['log_group_name'],
        module=module)
    final_log_group_snake = []

    for log_group in desc_log_group['logGroups']:
        final_log_group_snake.append(camel_dict_to_snake_dict(log_group))

    desc_log_group_result = dict(changed=False,
                                 log_groups=final_log_group_snake)
    module.exit_json(**desc_log_group_result)
Пример #25
0
def main():
    argument_spec = dict(
        name=dict(required=False),
    )
    module = AnsibleAWSModule(argument_spec=argument_spec, supports_check_mode=True)
    if module._name == 'elasticache_facts':
        module.deprecate("The 'elasticache_facts' module has been renamed to 'elasticache_info'", date='2021-12-01', collection_name='community.aws')

    client = module.client('elasticache')

    module.exit_json(elasticache_clusters=get_elasticache_clusters(client, module))
Пример #26
0
def main():
    argument_spec = dict(
        filters=dict(default=dict(), type='dict'),
        peer_connection_ids=dict(default=None, type='list', elements='str'),
    )

    module = AnsibleAWSModule(
        argument_spec=argument_spec,
        supports_check_mode=True,
    )
    if module._name == 'ec2_vpc_peering_facts':
        module.deprecate(
            "The 'ec2_vpc_peering_facts' module has been renamed to 'ec2_vpc_peering_info'",
            date='2021-12-01',
            collection_name='community.aws')

    try:
        region, ec2_url, aws_connect_kwargs = get_aws_connection_info(
            module, boto3=True)
    except NameError as e:
        # Getting around the get_aws_connection_info boto reliance for region
        if "global name 'boto' is not defined" in to_native(e):
            module.params['region'] = botocore.session.get_session(
            ).get_config_variable('region')
            if not module.params['region']:
                module.fail_json(msg="Error - no region provided")
        else:
            module.fail_json(msg="Can't retrieve connection information - " +
                             str(e))

    try:
        region, ec2_url, aws_connect_kwargs = get_aws_connection_info(
            module, boto3=True)
        ec2 = boto3_conn(module,
                         conn_type='client',
                         resource='ec2',
                         region=region,
                         endpoint=ec2_url,
                         **aws_connect_kwargs)
    except botocore.exceptions.NoCredentialsError as e:
        module.fail_json(msg=str(e))

    # Turn the boto3 result in to ansible friendly_snaked_names
    results = [
        camel_dict_to_snake_dict(peer) for peer in get_vpc_peers(ec2, module)
    ]

    # Turn the boto3 result in to ansible friendly tag dictionary
    for peer in results:
        peer['tags'] = boto3_tag_list_to_ansible_dict(peer.get('tags', []))

    module.exit_json(result=results)
Пример #27
0
def main():
    argument_spec = dict(
        iam_type=dict(required=True, choices=['user', 'group', 'role']),
        state=dict(default='present', choices=['present', 'absent']),
        iam_name=dict(required=True),
        policy_name=dict(required=True),
        policy_document=dict(default=None, required=False),
        policy_json=dict(type='json', default=None, required=False),
        skip_duplicates=dict(type='bool', default=None, required=False)
    )
    mutually_exclusive = [['policy_document', 'policy_json']]

    module = AnsibleAWSModule(argument_spec=argument_spec, mutually_exclusive=mutually_exclusive, supports_check_mode=True)

    skip_duplicates = module.params.get('skip_duplicates')

    if (skip_duplicates is None):
        module.deprecate('The skip_duplicates behaviour has caused confusion and'
                         ' will be disabled by default in Ansible 2.14',
                         date='2022-06-01', collection_name='community.aws')
        skip_duplicates = True

    if module.params.get('policy_document'):
        module.deprecate('The policy_document option has been deprecated and'
                         ' will be removed in Ansible 2.14',
                         date='2022-06-01', collection_name='community.aws')

    args = dict(
        client=module.client('iam'),
        name=module.params.get('iam_name'),
        policy_name=module.params.get('policy_name'),
        policy_document=module.params.get('policy_document'),
        policy_json=module.params.get('policy_json'),
        skip_duplicates=skip_duplicates,
        state=module.params.get('state'),
        check_mode=module.check_mode,
    )
    iam_type = module.params.get('iam_type')

    try:
        if iam_type == 'user':
            policy = UserPolicy(**args)
        elif iam_type == 'role':
            policy = RolePolicy(**args)
        elif iam_type == 'group':
            policy = GroupPolicy(**args)

        module.exit_json(**(policy.run()))
    except (BotoCoreError, ClientError) as e:
        module.fail_json_aws(e)
    except PolicyError as e:
        module.fail_json(msg=str(e))
Пример #28
0
def main():

    argument_spec = dict(
        nacl_ids=dict(default=[], type='list', aliases=['nacl_id'], elements='str'),
        filters=dict(default={}, type='dict'))

    module = AnsibleAWSModule(argument_spec=argument_spec, supports_check_mode=True)
    if module._name == 'ec2_vpc_nacl_facts':
        module.deprecate("The 'ec2_vpc_nacl_facts' module has been renamed to 'ec2_vpc_nacl_info'", date='2021-12-01', collection_name='community.aws')

    connection = module.client('ec2', retry_decorator=AWSRetry.jittered_backoff())

    list_ec2_vpc_nacls(connection, module)
Пример #29
0
def main():
    argument_spec = dict(
        vpc_id=dict(),
        vpc_endpoint_type=dict(
            default='Gateway',
            choices=['Interface', 'Gateway', 'GatewayLoadBalancer']),
        service=dict(),
        policy=dict(type='json'),
        policy_file=dict(type='path', aliases=['policy_path']),
        state=dict(default='present', choices=['present', 'absent']),
        wait=dict(type='bool', default=False),
        wait_timeout=dict(type='int', default=320, required=False),
        route_table_ids=dict(type='list', elements='str'),
        vpc_endpoint_id=dict(),
        client_token=dict(no_log=False),
        tags=dict(type='dict'),
        purge_tags=dict(type='bool', default=False),
    )
    module = AnsibleAWSModule(
        argument_spec=argument_spec,
        supports_check_mode=True,
        mutually_exclusive=[['policy', 'policy_file']],
        required_if=[
            ['state', 'present', ['vpc_id', 'service']],
            ['state', 'absent', ['vpc_endpoint_id']],
        ],
    )

    # Validate Requirements
    state = module.params.get('state')

    if module.params.get('policy_file'):
        module.deprecate(
            'The policy_file option has been deprecated and'
            ' will be removed after 2022-12-01',
            date='2022-12-01',
            collection_name='community.aws')

    try:
        ec2 = module.client('ec2', retry_decorator=AWSRetry.jittered_backoff())
    except (botocore.exceptions.ClientError,
            botocore.exceptions.BotoCoreError) as e:
        module.fail_json_aws(e, msg='Failed to connect to AWS')

    # Ensure resource is present
    if state == 'present':
        (changed, results) = setup_creation(ec2, module)
    else:
        (changed, results) = setup_removal(ec2, module)

    module.exit_json(changed=changed, result=results)
def main():
    argument_spec = dict(
        filters=dict(default=None, type='dict'),
    )

    module = AnsibleAWSModule(argument_spec=argument_spec,
                              supports_check_mode=True)
    if module._name == 'ec2_vpc_route_table_facts':
        module.deprecate("The 'ec2_vpc_route_table_facts' module has been renamed to 'ec2_vpc_route_table_info'",
                         date='2021-12-01', collection_name='amazon.aws')

    connection = module.client('ec2', retry_decorator=AWSRetry.jittered_backoff(retries=10))

    list_ec2_vpc_route_tables(connection, module)