From 742aefa700e3c796584b7ae4e9c44c38ca537b27 Mon Sep 17 00:00:00 2001 From: Mark Chappell Date: Fri, 15 Jan 2021 17:04:27 +0100 Subject: [PATCH 1/5] Split imports and reorder --- plugins/modules/aws_config_delivery_channel.py | 6 ++++-- plugins/modules/aws_config_recorder.py | 6 ++++-- plugins/modules/aws_config_rule.py | 6 ++++-- plugins/modules/cloudformation_stack_set.py | 17 +++++++++-------- .../cloudfront_origin_access_identity.py | 9 +++++---- .../cloudwatchlogs_log_group_metric_filter.py | 7 +++++-- plugins/modules/ec2_ami_copy.py | 11 ++++++----- plugins/modules/ec2_instance.py | 12 ++++++------ plugins/modules/ec2_instance_info.py | 3 +-- plugins/modules/ec2_vpc_endpoint_info.py | 3 ++- plugins/modules/ecs_cluster.py | 1 + plugins/modules/ecs_taskdefinition.py | 3 ++- plugins/modules/elasticache_parameter_group.py | 1 - plugins/modules/elb_application_lb_info.py | 1 + plugins/modules/elb_target.py | 4 ++-- plugins/modules/elb_target_group_info.py | 1 + plugins/modules/iam_user_info.py | 7 ++++--- plugins/modules/route53_health_check.py | 3 +-- plugins/modules/route53_info.py | 1 + plugins/modules/s3_metrics_configuration.py | 6 ++++-- 20 files changed, 63 insertions(+), 45 deletions(-) diff --git a/plugins/modules/aws_config_delivery_channel.py b/plugins/modules/aws_config_delivery_channel.py index 6e7fe5b2fa9..fa9fbab73af 100644 --- a/plugins/modules/aws_config_delivery_channel.py +++ b/plugins/modules/aws_config_delivery_channel.py @@ -72,8 +72,10 @@ except ImportError: pass # handled by AnsibleAWSModule -from ansible_collections.amazon.aws.plugins.module_utils.core import AnsibleAWSModule, is_boto3_error_code -from ansible_collections.amazon.aws.plugins.module_utils.ec2 import camel_dict_to_snake_dict, AWSRetry +from ansible_collections.amazon.aws.plugins.module_utils.core import AnsibleAWSModule +from ansible_collections.amazon.aws.plugins.module_utils.core import is_boto3_error_code +from ansible_collections.amazon.aws.plugins.module_utils.ec2 import AWSRetry +from ansible_collections.amazon.aws.plugins.module_utils.ec2 import camel_dict_to_snake_dict # this waits for an IAM role to become fully available, at the cost of diff --git a/plugins/modules/aws_config_recorder.py b/plugins/modules/aws_config_recorder.py index 2d3bf003d3b..5e8e4575efd 100644 --- a/plugins/modules/aws_config_recorder.py +++ b/plugins/modules/aws_config_recorder.py @@ -86,8 +86,10 @@ except ImportError: pass # handled by AnsibleAWSModule -from ansible_collections.amazon.aws.plugins.module_utils.core import AnsibleAWSModule, is_boto3_error_code -from ansible_collections.amazon.aws.plugins.module_utils.ec2 import camel_dict_to_snake_dict, AWSRetry +from ansible_collections.amazon.aws.plugins.module_utils.core import AnsibleAWSModule +from ansible_collections.amazon.aws.plugins.module_utils.core import is_boto3_error_code +from ansible_collections.amazon.aws.plugins.module_utils.ec2 import AWSRetry +from ansible_collections.amazon.aws.plugins.module_utils.ec2 import camel_dict_to_snake_dict def resource_exists(client, module, params): diff --git a/plugins/modules/aws_config_rule.py b/plugins/modules/aws_config_rule.py index 80550586aa8..b9bdc62a544 100644 --- a/plugins/modules/aws_config_rule.py +++ b/plugins/modules/aws_config_rule.py @@ -114,8 +114,10 @@ except ImportError: pass # handled by AnsibleAWSModule -from ansible_collections.amazon.aws.plugins.module_utils.core import AnsibleAWSModule, is_boto3_error_code -from ansible_collections.amazon.aws.plugins.module_utils.ec2 import AWSRetry, camel_dict_to_snake_dict +from ansible_collections.amazon.aws.plugins.module_utils.core import AnsibleAWSModule +from ansible_collections.amazon.aws.plugins.module_utils.core import is_boto3_error_code +from ansible_collections.amazon.aws.plugins.module_utils.ec2 import AWSRetry +from ansible_collections.amazon.aws.plugins.module_utils.ec2 import camel_dict_to_snake_dict def rule_exists(client, module, params): diff --git a/plugins/modules/cloudformation_stack_set.py b/plugins/modules/cloudformation_stack_set.py index 148cbe61047..fad896acf38 100644 --- a/plugins/modules/cloudformation_stack_set.py +++ b/plugins/modules/cloudformation_stack_set.py @@ -296,10 +296,10 @@ ''' # NOQA -import time import datetime -import uuid import itertools +import time +import uuid try: import boto3 @@ -309,14 +309,15 @@ # handled by AnsibleAWSModule pass -from ansible_collections.amazon.aws.plugins.module_utils.ec2 import (AWSRetry, - boto3_tag_list_to_ansible_dict, - ansible_dict_to_boto3_tag_list, - camel_dict_to_snake_dict, - ) -from ansible_collections.amazon.aws.plugins.module_utils.core import AnsibleAWSModule, is_boto3_error_code from ansible.module_utils._text import to_native +from ansible_collections.amazon.aws.plugins.module_utils.core import AnsibleAWSModule +from ansible_collections.amazon.aws.plugins.module_utils.core import is_boto3_error_code +from ansible_collections.amazon.aws.plugins.module_utils.ec2 import AWSRetry +from ansible_collections.amazon.aws.plugins.module_utils.ec2 import ansible_dict_to_boto3_tag_list +from ansible_collections.amazon.aws.plugins.module_utils.ec2 import boto3_tag_list_to_ansible_dict +from ansible_collections.amazon.aws.plugins.module_utils.ec2 import camel_dict_to_snake_dict + def create_stack_set(module, stack_params, cfn): try: diff --git a/plugins/modules/cloudfront_origin_access_identity.py b/plugins/modules/cloudfront_origin_access_identity.py index 00f188222c5..425c104d9b5 100644 --- a/plugins/modules/cloudfront_origin_access_identity.py +++ b/plugins/modules/cloudfront_origin_access_identity.py @@ -120,9 +120,6 @@ ''' -from ansible_collections.amazon.aws.plugins.module_utils.cloudfront_facts import CloudFrontFactsServiceManager -from ansible_collections.amazon.aws.plugins.module_utils.ec2 import camel_dict_to_snake_dict -from ansible_collections.amazon.aws.plugins.module_utils.core import AnsibleAWSModule import datetime from functools import partial import json @@ -130,11 +127,15 @@ try: import botocore - from botocore.signers import CloudFrontSigner from botocore.exceptions import ClientError, BotoCoreError + from botocore.signers import CloudFrontSigner except ImportError: pass # caught by imported AnsibleAWSModule +from ansible_collections.amazon.aws.plugins.module_utils.cloudfront_facts import CloudFrontFactsServiceManager +from ansible_collections.amazon.aws.plugins.module_utils.core import AnsibleAWSModule +from ansible_collections.amazon.aws.plugins.module_utils.ec2 import camel_dict_to_snake_dict + class CloudFrontOriginAccessIdentityServiceManager(object): """ diff --git a/plugins/modules/cloudwatchlogs_log_group_metric_filter.py b/plugins/modules/cloudwatchlogs_log_group_metric_filter.py index a05c7fe2029..3d08995aeb7 100644 --- a/plugins/modules/cloudwatchlogs_log_group_metric_filter.py +++ b/plugins/modules/cloudwatchlogs_log_group_metric_filter.py @@ -100,14 +100,17 @@ ] """ -from ansible_collections.amazon.aws.plugins.module_utils.core import AnsibleAWSModule, is_boto3_error_code, get_boto3_client_method_parameters -from ansible_collections.amazon.aws.plugins.module_utils.ec2 import camel_dict_to_snake_dict try: from botocore.exceptions import ClientError, BotoCoreError, WaiterError except ImportError: pass # caught by AnsibleAWSModule +from ansible_collections.amazon.aws.plugins.module_utils.core import AnsibleAWSModule +from ansible_collections.amazon.aws.plugins.module_utils.core import is_boto3_error_code +from ansible_collections.amazon.aws.plugins.module_utils.core import get_boto3_client_method_parameters +from ansible_collections.amazon.aws.plugins.module_utils.ec2 import camel_dict_to_snake_dict + def metricTransformationHandler(metricTransformations, originMetricTransformations=None): diff --git a/plugins/modules/ec2_ami_copy.py b/plugins/modules/ec2_ami_copy.py index 38f1123168f..e512bb71d3c 100644 --- a/plugins/modules/ec2_ami_copy.py +++ b/plugins/modules/ec2_ami_copy.py @@ -135,16 +135,17 @@ sample: ami-e689729e ''' -from ansible_collections.amazon.aws.plugins.module_utils.core import AnsibleAWSModule -from ansible_collections.amazon.aws.plugins.module_utils.ec2 import camel_dict_to_snake_dict -from ansible_collections.amazon.aws.plugins.module_utils.ec2 import ansible_dict_to_boto3_tag_list -from ansible.module_utils._text import to_native - try: from botocore.exceptions import ClientError, NoCredentialsError, WaiterError, BotoCoreError except ImportError: pass # caught by AnsibleAWSModule +from ansible.module_utils._text import to_native + +from ansible_collections.amazon.aws.plugins.module_utils.core import AnsibleAWSModule +from ansible_collections.amazon.aws.plugins.module_utils.ec2 import camel_dict_to_snake_dict +from ansible_collections.amazon.aws.plugins.module_utils.ec2 import ansible_dict_to_boto3_tag_list + def copy_image(module, ec2): """ diff --git a/plugins/modules/ec2_instance.py b/plugins/modules/ec2_instance.py index aba7ac26b10..0844355f511 100644 --- a/plugins/modules/ec2_instance.py +++ b/plugins/modules/ec2_instance.py @@ -795,12 +795,12 @@ sample: vpc-0011223344 ''' +from collections import namedtuple import re -import uuid import string import textwrap import time -from collections import namedtuple +import uuid try: import boto3 @@ -808,18 +808,18 @@ except ImportError: pass # caught by AnsibleAWSModule -from ansible.module_utils.six import string_types -from ansible.module_utils.six.moves.urllib import parse as urlparse from ansible.module_utils._text import to_bytes from ansible.module_utils._text import to_native +from ansible.module_utils.six import string_types +from ansible.module_utils.six.moves.urllib import parse as urlparse from ansible_collections.amazon.aws.plugins.module_utils.core import AnsibleAWSModule from ansible_collections.amazon.aws.plugins.module_utils.ec2 import AWSRetry from ansible_collections.amazon.aws.plugins.module_utils.ec2 import ansible_dict_to_boto3_filter_list -from ansible_collections.amazon.aws.plugins.module_utils.ec2 import compare_aws_tags -from ansible_collections.amazon.aws.plugins.module_utils.ec2 import boto3_tag_list_to_ansible_dict from ansible_collections.amazon.aws.plugins.module_utils.ec2 import ansible_dict_to_boto3_tag_list +from ansible_collections.amazon.aws.plugins.module_utils.ec2 import boto3_tag_list_to_ansible_dict from ansible_collections.amazon.aws.plugins.module_utils.ec2 import camel_dict_to_snake_dict +from ansible_collections.amazon.aws.plugins.module_utils.ec2 import compare_aws_tags from ansible_collections.amazon.aws.plugins.module_utils.ec2 import snake_dict_to_camel_dict module = None diff --git a/plugins/modules/ec2_instance_info.py b/plugins/modules/ec2_instance_info.py index e37f2cf9cd1..06548fae2e6 100644 --- a/plugins/modules/ec2_instance_info.py +++ b/plugins/modules/ec2_instance_info.py @@ -507,9 +507,8 @@ sample: vpc-0011223344 ''' -import traceback import datetime - +import traceback try: import boto3 diff --git a/plugins/modules/ec2_vpc_endpoint_info.py b/plugins/modules/ec2_vpc_endpoint_info.py index e72b487db3d..6d57fcb43d5 100644 --- a/plugins/modules/ec2_vpc_endpoint_info.py +++ b/plugins/modules/ec2_vpc_endpoint_info.py @@ -114,10 +114,11 @@ pass # Handled by AnsibleAWSModule from ansible.module_utils._text import to_native + from ansible_collections.amazon.aws.plugins.module_utils.core import AnsibleAWSModule +from ansible_collections.amazon.aws.plugins.module_utils.ec2 import AWSRetry from ansible_collections.amazon.aws.plugins.module_utils.ec2 import ansible_dict_to_boto3_filter_list from ansible_collections.amazon.aws.plugins.module_utils.ec2 import camel_dict_to_snake_dict -from ansible_collections.amazon.aws.plugins.module_utils.ec2 import AWSRetry def date_handler(obj): diff --git a/plugins/modules/ecs_cluster.py b/plugins/modules/ecs_cluster.py index ed0dc1c78ff..0cc51065a7a 100644 --- a/plugins/modules/ecs_cluster.py +++ b/plugins/modules/ecs_cluster.py @@ -103,6 +103,7 @@ type: str sample: ACTIVE ''' + import time try: diff --git a/plugins/modules/ecs_taskdefinition.py b/plugins/modules/ecs_taskdefinition.py index 6158fb4ec21..25907d1befa 100644 --- a/plugins/modules/ecs_taskdefinition.py +++ b/plugins/modules/ecs_taskdefinition.py @@ -213,9 +213,10 @@ except ImportError: pass # caught by AnsibleAWSModule +from ansible.module_utils._text import to_text + from ansible_collections.amazon.aws.plugins.module_utils.core import AnsibleAWSModule from ansible_collections.amazon.aws.plugins.module_utils.ec2 import camel_dict_to_snake_dict -from ansible.module_utils._text import to_text class EcsTaskManager: diff --git a/plugins/modules/elasticache_parameter_group.py b/plugins/modules/elasticache_parameter_group.py index 1e9c574178d..c206d4e4e40 100644 --- a/plugins/modules/elasticache_parameter_group.py +++ b/plugins/modules/elasticache_parameter_group.py @@ -116,7 +116,6 @@ from ansible.module_utils._text import to_text from ansible.module_utils.six import string_types -# import module snippets from ansible_collections.amazon.aws.plugins.module_utils.core import AnsibleAWSModule from ansible_collections.amazon.aws.plugins.module_utils.ec2 import camel_dict_to_snake_dict diff --git a/plugins/modules/elb_application_lb_info.py b/plugins/modules/elb_application_lb_info.py index 06e1f3ae229..39552670ac4 100644 --- a/plugins/modules/elb_application_lb_info.py +++ b/plugins/modules/elb_application_lb_info.py @@ -172,6 +172,7 @@ pass # Handled by AnsibleAWSModule from ansible.module_utils._text import to_native + from ansible_collections.amazon.aws.plugins.module_utils.core import AnsibleAWSModule from ansible_collections.amazon.aws.plugins.module_utils.core import is_boto3_error_code from ansible_collections.amazon.aws.plugins.module_utils.ec2 import boto3_tag_list_to_ansible_dict diff --git a/plugins/modules/elb_target.py b/plugins/modules/elb_target.py index b8cda233814..e6383ac568c 100644 --- a/plugins/modules/elb_target.py +++ b/plugins/modules/elb_target.py @@ -111,8 +111,8 @@ ''' -import traceback from time import time, sleep +import traceback try: import boto3 @@ -124,8 +124,8 @@ from ansible.module_utils._text import to_native from ansible_collections.amazon.aws.plugins.module_utils.core import AnsibleAWSModule -from ansible_collections.amazon.aws.plugins.module_utils.ec2 import camel_dict_to_snake_dict from ansible_collections.amazon.aws.plugins.module_utils.ec2 import AWSRetry +from ansible_collections.amazon.aws.plugins.module_utils.ec2 import camel_dict_to_snake_dict @AWSRetry.jittered_backoff(retries=10, delay=10, catch_extra_error_codes=['TargetGroupNotFound']) diff --git a/plugins/modules/elb_target_group_info.py b/plugins/modules/elb_target_group_info.py index a9694428872..4c17a437b31 100644 --- a/plugins/modules/elb_target_group_info.py +++ b/plugins/modules/elb_target_group_info.py @@ -217,6 +217,7 @@ pass # Handled by AnsibleAWSModule from ansible.module_utils._text import to_native + from ansible_collections.amazon.aws.plugins.module_utils.core import AnsibleAWSModule from ansible_collections.amazon.aws.plugins.module_utils.core import is_boto3_error_code from ansible_collections.amazon.aws.plugins.module_utils.ec2 import boto3_tag_list_to_ansible_dict diff --git a/plugins/modules/iam_user_info.py b/plugins/modules/iam_user_info.py index 8e1856b1763..16b88d11981 100644 --- a/plugins/modules/iam_user_info.py +++ b/plugins/modules/iam_user_info.py @@ -101,15 +101,16 @@ sample: "test_user" ''' -from ansible_collections.amazon.aws.plugins.module_utils.core import AnsibleAWSModule -from ansible_collections.amazon.aws.plugins.module_utils.ec2 import camel_dict_to_snake_dict, AWSRetry - try: import botocore from botocore.exceptions import BotoCoreError, ClientError except ImportError: pass # caught by AnsibleAWSModule +from ansible_collections.amazon.aws.plugins.module_utils.core import AnsibleAWSModule +from ansible_collections.amazon.aws.plugins.module_utils.ec2 import AWSRetry +from ansible_collections.amazon.aws.plugins.module_utils.ec2 import camel_dict_to_snake_dict + @AWSRetry.exponential_backoff() def list_iam_users_with_backoff(client, operation, **kwargs): diff --git a/plugins/modules/route53_health_check.py b/plugins/modules/route53_health_check.py index a1f9c9a268c..3cd441c42a0 100644 --- a/plugins/modules/route53_health_check.py +++ b/plugins/modules/route53_health_check.py @@ -126,10 +126,9 @@ except ImportError: pass # Handled by HAS_BOTO -# import module snippets from ansible_collections.amazon.aws.plugins.module_utils.core import AnsibleAWSModule -from ansible_collections.amazon.aws.plugins.module_utils.ec2 import get_aws_connection_info from ansible_collections.amazon.aws.plugins.module_utils.ec2 import HAS_BOTO +from ansible_collections.amazon.aws.plugins.module_utils.ec2 import get_aws_connection_info # Things that can't get changed: diff --git a/plugins/modules/route53_info.py b/plugins/modules/route53_info.py index 38d0bc540f5..d2e173749ba 100644 --- a/plugins/modules/route53_info.py +++ b/plugins/modules/route53_info.py @@ -204,6 +204,7 @@ start_record_name: "host1.workshop.test.io" register: RECORDS ''' + try: import boto import botocore diff --git a/plugins/modules/s3_metrics_configuration.py b/plugins/modules/s3_metrics_configuration.py index 729503cf88b..e99f414fcc5 100644 --- a/plugins/modules/s3_metrics_configuration.py +++ b/plugins/modules/s3_metrics_configuration.py @@ -101,8 +101,10 @@ except ImportError: pass # Handled by AnsibleAWSModule -from ansible_collections.amazon.aws.plugins.module_utils.core import AnsibleAWSModule, is_boto3_error_code -from ansible_collections.amazon.aws.plugins.module_utils.ec2 import AWSRetry, ansible_dict_to_boto3_tag_list +from ansible_collections.amazon.aws.plugins.module_utils.core import AnsibleAWSModule +from ansible_collections.amazon.aws.plugins.module_utils.core import is_boto3_error_code +from ansible_collections.amazon.aws.plugins.module_utils.ec2 import AWSRetry +from ansible_collections.amazon.aws.plugins.module_utils.ec2 import ansible_dict_to_boto3_tag_list def _create_metrics_configuration(mc_id, filter_prefix, filter_tags): From ce4004df0f4b92e47d992c92aa52ffe7b6ef81de Mon Sep 17 00:00:00 2001 From: Mark Chappell Date: Fri, 15 Jan 2021 17:09:40 +0100 Subject: [PATCH 2/5] Import camel_dict_to_snake_dict and snake_dict_to_camel_dict direct from ansible.module_utils.common.dict_transformations --- plugins/modules/aws_config_delivery_channel.py | 3 ++- plugins/modules/aws_config_recorder.py | 3 ++- plugins/modules/aws_config_rule.py | 3 ++- plugins/modules/cloudformation_stack_set.py | 2 +- plugins/modules/cloudfront_origin_access_identity.py | 3 ++- plugins/modules/cloudwatchlogs_log_group_metric_filter.py | 3 ++- plugins/modules/ec2_ami_copy.py | 2 +- plugins/modules/ec2_customer_gateway.py | 3 ++- plugins/modules/ec2_instance.py | 4 ++-- plugins/modules/ec2_instance_info.py | 3 ++- plugins/modules/ec2_lc_info.py | 3 ++- plugins/modules/ec2_snapshot_copy.py | 2 +- plugins/modules/ec2_vpc_endpoint_info.py | 2 +- plugins/modules/ecs_taskdefinition.py | 2 +- plugins/modules/elasticache_parameter_group.py | 2 +- plugins/modules/elb_application_lb_info.py | 2 +- plugins/modules/elb_target.py | 2 +- plugins/modules/elb_target_group_info.py | 2 +- plugins/modules/iam_mfa_device_info.py | 3 ++- plugins/modules/iam_user_info.py | 3 ++- plugins/modules/lambda_event.py | 3 ++- plugins/modules/s3_website.py | 3 ++- 22 files changed, 35 insertions(+), 23 deletions(-) diff --git a/plugins/modules/aws_config_delivery_channel.py b/plugins/modules/aws_config_delivery_channel.py index fa9fbab73af..f13a0899a20 100644 --- a/plugins/modules/aws_config_delivery_channel.py +++ b/plugins/modules/aws_config_delivery_channel.py @@ -72,10 +72,11 @@ except ImportError: pass # handled by AnsibleAWSModule +from ansible.module_utils.common.dict_transformations import camel_dict_to_snake_dict + from ansible_collections.amazon.aws.plugins.module_utils.core import AnsibleAWSModule from ansible_collections.amazon.aws.plugins.module_utils.core import is_boto3_error_code from ansible_collections.amazon.aws.plugins.module_utils.ec2 import AWSRetry -from ansible_collections.amazon.aws.plugins.module_utils.ec2 import camel_dict_to_snake_dict # this waits for an IAM role to become fully available, at the cost of diff --git a/plugins/modules/aws_config_recorder.py b/plugins/modules/aws_config_recorder.py index 5e8e4575efd..af5de6f938a 100644 --- a/plugins/modules/aws_config_recorder.py +++ b/plugins/modules/aws_config_recorder.py @@ -86,10 +86,11 @@ except ImportError: pass # handled by AnsibleAWSModule +from ansible.module_utils.common.dict_transformations import camel_dict_to_snake_dict + from ansible_collections.amazon.aws.plugins.module_utils.core import AnsibleAWSModule from ansible_collections.amazon.aws.plugins.module_utils.core import is_boto3_error_code from ansible_collections.amazon.aws.plugins.module_utils.ec2 import AWSRetry -from ansible_collections.amazon.aws.plugins.module_utils.ec2 import camel_dict_to_snake_dict def resource_exists(client, module, params): diff --git a/plugins/modules/aws_config_rule.py b/plugins/modules/aws_config_rule.py index b9bdc62a544..ee606f99e06 100644 --- a/plugins/modules/aws_config_rule.py +++ b/plugins/modules/aws_config_rule.py @@ -114,10 +114,11 @@ except ImportError: pass # handled by AnsibleAWSModule +from ansible.module_utils.common.dict_transformations import camel_dict_to_snake_dict + from ansible_collections.amazon.aws.plugins.module_utils.core import AnsibleAWSModule from ansible_collections.amazon.aws.plugins.module_utils.core import is_boto3_error_code from ansible_collections.amazon.aws.plugins.module_utils.ec2 import AWSRetry -from ansible_collections.amazon.aws.plugins.module_utils.ec2 import camel_dict_to_snake_dict def rule_exists(client, module, params): diff --git a/plugins/modules/cloudformation_stack_set.py b/plugins/modules/cloudformation_stack_set.py index fad896acf38..cda0a2bf9fe 100644 --- a/plugins/modules/cloudformation_stack_set.py +++ b/plugins/modules/cloudformation_stack_set.py @@ -310,13 +310,13 @@ pass from ansible.module_utils._text import to_native +from ansible.module_utils.common.dict_transformations import camel_dict_to_snake_dict from ansible_collections.amazon.aws.plugins.module_utils.core import AnsibleAWSModule from ansible_collections.amazon.aws.plugins.module_utils.core import is_boto3_error_code from ansible_collections.amazon.aws.plugins.module_utils.ec2 import AWSRetry from ansible_collections.amazon.aws.plugins.module_utils.ec2 import ansible_dict_to_boto3_tag_list from ansible_collections.amazon.aws.plugins.module_utils.ec2 import boto3_tag_list_to_ansible_dict -from ansible_collections.amazon.aws.plugins.module_utils.ec2 import camel_dict_to_snake_dict def create_stack_set(module, stack_params, cfn): diff --git a/plugins/modules/cloudfront_origin_access_identity.py b/plugins/modules/cloudfront_origin_access_identity.py index 425c104d9b5..8b98bd99cdb 100644 --- a/plugins/modules/cloudfront_origin_access_identity.py +++ b/plugins/modules/cloudfront_origin_access_identity.py @@ -132,9 +132,10 @@ except ImportError: pass # caught by imported AnsibleAWSModule +from ansible.module_utils.common.dict_transformations import camel_dict_to_snake_dict + from ansible_collections.amazon.aws.plugins.module_utils.cloudfront_facts import CloudFrontFactsServiceManager from ansible_collections.amazon.aws.plugins.module_utils.core import AnsibleAWSModule -from ansible_collections.amazon.aws.plugins.module_utils.ec2 import camel_dict_to_snake_dict class CloudFrontOriginAccessIdentityServiceManager(object): diff --git a/plugins/modules/cloudwatchlogs_log_group_metric_filter.py b/plugins/modules/cloudwatchlogs_log_group_metric_filter.py index 3d08995aeb7..0573f8d4f0a 100644 --- a/plugins/modules/cloudwatchlogs_log_group_metric_filter.py +++ b/plugins/modules/cloudwatchlogs_log_group_metric_filter.py @@ -106,10 +106,11 @@ except ImportError: pass # caught by AnsibleAWSModule +from ansible.module_utils.common.dict_transformations import camel_dict_to_snake_dict + from ansible_collections.amazon.aws.plugins.module_utils.core import AnsibleAWSModule from ansible_collections.amazon.aws.plugins.module_utils.core import is_boto3_error_code from ansible_collections.amazon.aws.plugins.module_utils.core import get_boto3_client_method_parameters -from ansible_collections.amazon.aws.plugins.module_utils.ec2 import camel_dict_to_snake_dict def metricTransformationHandler(metricTransformations, originMetricTransformations=None): diff --git a/plugins/modules/ec2_ami_copy.py b/plugins/modules/ec2_ami_copy.py index e512bb71d3c..531d28726c1 100644 --- a/plugins/modules/ec2_ami_copy.py +++ b/plugins/modules/ec2_ami_copy.py @@ -141,9 +141,9 @@ pass # caught by AnsibleAWSModule from ansible.module_utils._text import to_native +from ansible.module_utils.common.dict_transformations import camel_dict_to_snake_dict from ansible_collections.amazon.aws.plugins.module_utils.core import AnsibleAWSModule -from ansible_collections.amazon.aws.plugins.module_utils.ec2 import camel_dict_to_snake_dict from ansible_collections.amazon.aws.plugins.module_utils.ec2 import ansible_dict_to_boto3_tag_list diff --git a/plugins/modules/ec2_customer_gateway.py b/plugins/modules/ec2_customer_gateway.py index 1e9fc1ded47..d42fa2b8541 100644 --- a/plugins/modules/ec2_customer_gateway.py +++ b/plugins/modules/ec2_customer_gateway.py @@ -116,9 +116,10 @@ except ImportError: pass # Handled by AnsibleAWSModule +from ansible.module_utils.common.dict_transformations import camel_dict_to_snake_dict + from ansible_collections.amazon.aws.plugins.module_utils.core import AnsibleAWSModule from ansible_collections.amazon.aws.plugins.module_utils.ec2 import AWSRetry -from ansible_collections.amazon.aws.plugins.module_utils.ec2 import camel_dict_to_snake_dict class Ec2CustomerGatewayManager: diff --git a/plugins/modules/ec2_instance.py b/plugins/modules/ec2_instance.py index 0844355f511..ec9e64d7882 100644 --- a/plugins/modules/ec2_instance.py +++ b/plugins/modules/ec2_instance.py @@ -810,6 +810,8 @@ from ansible.module_utils._text import to_bytes from ansible.module_utils._text import to_native +from ansible.module_utils.common.dict_transformations import camel_dict_to_snake_dict +from ansible.module_utils.common.dict_transformations import snake_dict_to_camel_dict from ansible.module_utils.six import string_types from ansible.module_utils.six.moves.urllib import parse as urlparse @@ -818,9 +820,7 @@ from ansible_collections.amazon.aws.plugins.module_utils.ec2 import ansible_dict_to_boto3_filter_list from ansible_collections.amazon.aws.plugins.module_utils.ec2 import ansible_dict_to_boto3_tag_list from ansible_collections.amazon.aws.plugins.module_utils.ec2 import boto3_tag_list_to_ansible_dict -from ansible_collections.amazon.aws.plugins.module_utils.ec2 import camel_dict_to_snake_dict from ansible_collections.amazon.aws.plugins.module_utils.ec2 import compare_aws_tags -from ansible_collections.amazon.aws.plugins.module_utils.ec2 import snake_dict_to_camel_dict module = None diff --git a/plugins/modules/ec2_instance_info.py b/plugins/modules/ec2_instance_info.py index 06548fae2e6..5a2244d93c6 100644 --- a/plugins/modules/ec2_instance_info.py +++ b/plugins/modules/ec2_instance_info.py @@ -517,10 +517,11 @@ except ImportError: pass # Handled by AnsibleAWSModule +from ansible.module_utils.common.dict_transformations import camel_dict_to_snake_dict + from ansible_collections.amazon.aws.plugins.module_utils.core import AnsibleAWSModule from ansible_collections.amazon.aws.plugins.module_utils.ec2 import ansible_dict_to_boto3_filter_list from ansible_collections.amazon.aws.plugins.module_utils.ec2 import boto3_tag_list_to_ansible_dict -from ansible_collections.amazon.aws.plugins.module_utils.ec2 import camel_dict_to_snake_dict def list_ec2_instances(connection, module): diff --git a/plugins/modules/ec2_lc_info.py b/plugins/modules/ec2_lc_info.py index 1d680c37bc9..922274abc46 100644 --- a/plugins/modules/ec2_lc_info.py +++ b/plugins/modules/ec2_lc_info.py @@ -158,8 +158,9 @@ except ImportError: pass # Handled by AnsibleAWSModule +from ansible.module_utils.common.dict_transformations import camel_dict_to_snake_dict + from ansible_collections.amazon.aws.plugins.module_utils.core import AnsibleAWSModule -from ansible_collections.amazon.aws.plugins.module_utils.ec2 import camel_dict_to_snake_dict def list_launch_configs(connection, module): diff --git a/plugins/modules/ec2_snapshot_copy.py b/plugins/modules/ec2_snapshot_copy.py index 85f44d60000..d6aa84a7c04 100644 --- a/plugins/modules/ec2_snapshot_copy.py +++ b/plugins/modules/ec2_snapshot_copy.py @@ -119,9 +119,9 @@ pass # Handled by AnsibleAWSModule from ansible.module_utils._text import to_native +from ansible.module_utils.common.dict_transformations import camel_dict_to_snake_dict from ansible_collections.amazon.aws.plugins.module_utils.core import AnsibleAWSModule -from ansible_collections.amazon.aws.plugins.module_utils.ec2 import camel_dict_to_snake_dict def copy_snapshot(module, ec2): diff --git a/plugins/modules/ec2_vpc_endpoint_info.py b/plugins/modules/ec2_vpc_endpoint_info.py index 6d57fcb43d5..4ce142f5733 100644 --- a/plugins/modules/ec2_vpc_endpoint_info.py +++ b/plugins/modules/ec2_vpc_endpoint_info.py @@ -114,11 +114,11 @@ pass # Handled by AnsibleAWSModule from ansible.module_utils._text import to_native +from ansible.module_utils.common.dict_transformations import camel_dict_to_snake_dict from ansible_collections.amazon.aws.plugins.module_utils.core import AnsibleAWSModule from ansible_collections.amazon.aws.plugins.module_utils.ec2 import AWSRetry from ansible_collections.amazon.aws.plugins.module_utils.ec2 import ansible_dict_to_boto3_filter_list -from ansible_collections.amazon.aws.plugins.module_utils.ec2 import camel_dict_to_snake_dict def date_handler(obj): diff --git a/plugins/modules/ecs_taskdefinition.py b/plugins/modules/ecs_taskdefinition.py index 25907d1befa..33fa0203dda 100644 --- a/plugins/modules/ecs_taskdefinition.py +++ b/plugins/modules/ecs_taskdefinition.py @@ -214,9 +214,9 @@ pass # caught by AnsibleAWSModule from ansible.module_utils._text import to_text +from ansible.module_utils.common.dict_transformations import camel_dict_to_snake_dict from ansible_collections.amazon.aws.plugins.module_utils.core import AnsibleAWSModule -from ansible_collections.amazon.aws.plugins.module_utils.ec2 import camel_dict_to_snake_dict class EcsTaskManager: diff --git a/plugins/modules/elasticache_parameter_group.py b/plugins/modules/elasticache_parameter_group.py index c206d4e4e40..52f77da267d 100644 --- a/plugins/modules/elasticache_parameter_group.py +++ b/plugins/modules/elasticache_parameter_group.py @@ -114,10 +114,10 @@ pass # Handled by AnsibleAWSModule from ansible.module_utils._text import to_text +from ansible.module_utils.common.dict_transformations import camel_dict_to_snake_dict from ansible.module_utils.six import string_types from ansible_collections.amazon.aws.plugins.module_utils.core import AnsibleAWSModule -from ansible_collections.amazon.aws.plugins.module_utils.ec2 import camel_dict_to_snake_dict def create(module, conn, name, group_family, description): diff --git a/plugins/modules/elb_application_lb_info.py b/plugins/modules/elb_application_lb_info.py index 39552670ac4..f3580dee58b 100644 --- a/plugins/modules/elb_application_lb_info.py +++ b/plugins/modules/elb_application_lb_info.py @@ -172,11 +172,11 @@ pass # Handled by AnsibleAWSModule from ansible.module_utils._text import to_native +from ansible.module_utils.common.dict_transformations import camel_dict_to_snake_dict from ansible_collections.amazon.aws.plugins.module_utils.core import AnsibleAWSModule from ansible_collections.amazon.aws.plugins.module_utils.core import is_boto3_error_code from ansible_collections.amazon.aws.plugins.module_utils.ec2 import boto3_tag_list_to_ansible_dict -from ansible_collections.amazon.aws.plugins.module_utils.ec2 import camel_dict_to_snake_dict def get_elb_listeners(connection, module, elb_arn): diff --git a/plugins/modules/elb_target.py b/plugins/modules/elb_target.py index e6383ac568c..4f81611fd2e 100644 --- a/plugins/modules/elb_target.py +++ b/plugins/modules/elb_target.py @@ -122,10 +122,10 @@ pass # Handled by AnsibleAWSModule from ansible.module_utils._text import to_native +from ansible.module_utils.common.dict_transformations import camel_dict_to_snake_dict from ansible_collections.amazon.aws.plugins.module_utils.core import AnsibleAWSModule from ansible_collections.amazon.aws.plugins.module_utils.ec2 import AWSRetry -from ansible_collections.amazon.aws.plugins.module_utils.ec2 import camel_dict_to_snake_dict @AWSRetry.jittered_backoff(retries=10, delay=10, catch_extra_error_codes=['TargetGroupNotFound']) diff --git a/plugins/modules/elb_target_group_info.py b/plugins/modules/elb_target_group_info.py index 4c17a437b31..16d5816afc0 100644 --- a/plugins/modules/elb_target_group_info.py +++ b/plugins/modules/elb_target_group_info.py @@ -217,11 +217,11 @@ pass # Handled by AnsibleAWSModule from ansible.module_utils._text import to_native +from ansible.module_utils.common.dict_transformations import camel_dict_to_snake_dict from ansible_collections.amazon.aws.plugins.module_utils.core import AnsibleAWSModule from ansible_collections.amazon.aws.plugins.module_utils.core import is_boto3_error_code from ansible_collections.amazon.aws.plugins.module_utils.ec2 import boto3_tag_list_to_ansible_dict -from ansible_collections.amazon.aws.plugins.module_utils.ec2 import camel_dict_to_snake_dict def get_target_group_attributes(connection, module, target_group_arn): diff --git a/plugins/modules/iam_mfa_device_info.py b/plugins/modules/iam_mfa_device_info.py index c79afab095f..52f183edf15 100644 --- a/plugins/modules/iam_mfa_device_info.py +++ b/plugins/modules/iam_mfa_device_info.py @@ -67,8 +67,9 @@ except ImportError: pass # Handled by AnsibleAWSModule +from ansible.module_utils.common.dict_transformations import camel_dict_to_snake_dict + from ansible_collections.amazon.aws.plugins.module_utils.core import AnsibleAWSModule -from ansible_collections.amazon.aws.plugins.module_utils.ec2 import camel_dict_to_snake_dict def list_mfa_devices(connection, module): diff --git a/plugins/modules/iam_user_info.py b/plugins/modules/iam_user_info.py index 16b88d11981..00c9368dc37 100644 --- a/plugins/modules/iam_user_info.py +++ b/plugins/modules/iam_user_info.py @@ -107,9 +107,10 @@ except ImportError: pass # caught by AnsibleAWSModule +from ansible.module_utils.common.dict_transformations import camel_dict_to_snake_dict + from ansible_collections.amazon.aws.plugins.module_utils.core import AnsibleAWSModule from ansible_collections.amazon.aws.plugins.module_utils.ec2 import AWSRetry -from ansible_collections.amazon.aws.plugins.module_utils.ec2 import camel_dict_to_snake_dict @AWSRetry.exponential_backoff() diff --git a/plugins/modules/lambda_event.py b/plugins/modules/lambda_event.py index e0009d13582..26365d78407 100644 --- a/plugins/modules/lambda_event.py +++ b/plugins/modules/lambda_event.py @@ -123,9 +123,10 @@ except ImportError: pass # Handled by AnsibleAWSModule +from ansible.module_utils.common.dict_transformations import camel_dict_to_snake_dict + from ansible_collections.amazon.aws.plugins.module_utils.core import AnsibleAWSModule from ansible_collections.amazon.aws.plugins.module_utils.ec2 import boto3_conn -from ansible_collections.amazon.aws.plugins.module_utils.ec2 import camel_dict_to_snake_dict from ansible_collections.amazon.aws.plugins.module_utils.ec2 import get_aws_connection_info diff --git a/plugins/modules/s3_website.py b/plugins/modules/s3_website.py index 6f7aa898391..31071265f92 100644 --- a/plugins/modules/s3_website.py +++ b/plugins/modules/s3_website.py @@ -168,9 +168,10 @@ except ImportError: pass # Handled by AnsibleAWSModule +from ansible.module_utils.common.dict_transformations import camel_dict_to_snake_dict + from ansible_collections.amazon.aws.plugins.module_utils.core import AnsibleAWSModule from ansible_collections.amazon.aws.plugins.module_utils.core import is_boto3_error_code -from ansible_collections.amazon.aws.plugins.module_utils.ec2 import camel_dict_to_snake_dict def _create_redirect_dict(url): From 6528864ce608d5b0ffd50b409b91dd2f83202e2d Mon Sep 17 00:00:00 2001 From: Mark Chappell Date: Fri, 15 Jan 2021 17:28:23 +0100 Subject: [PATCH 3/5] Remove unused imports --- plugins/modules/aws_config_aggregation_authorization.py | 1 - plugins/modules/aws_config_delivery_channel.py | 1 - plugins/modules/aws_config_recorder.py | 1 - plugins/modules/aws_config_rule.py | 1 - plugins/modules/cloudformation_stack_set.py | 2 -- plugins/modules/cloudfront_origin_access_identity.py | 5 ----- plugins/modules/cloudwatchlogs_log_group_metric_filter.py | 7 ------- plugins/modules/dynamodb_ttl.py | 2 -- plugins/modules/ec2_ami_copy.py | 2 +- plugins/modules/ec2_customer_gateway.py | 2 -- plugins/modules/ec2_elb.py | 1 - plugins/modules/ec2_instance.py | 2 -- plugins/modules/ec2_instance_info.py | 2 -- plugins/modules/ec2_lc_info.py | 1 - plugins/modules/ec2_snapshot_copy.py | 2 -- plugins/modules/ec2_vpc_endpoint_info.py | 1 - plugins/modules/ec2_vpc_vgw.py | 1 - plugins/modules/ecs_attribute.py | 1 - plugins/modules/ecs_cluster.py | 1 - plugins/modules/ecs_taskdefinition.py | 1 - plugins/modules/elasticache_parameter_group.py | 1 - plugins/modules/elb_application_lb_info.py | 1 - plugins/modules/elb_instance.py | 1 - plugins/modules/elb_target.py | 1 - plugins/modules/elb_target_group_info.py | 1 - plugins/modules/iam_mfa_device_info.py | 1 - plugins/modules/iam_server_certificate_info.py | 1 - plugins/modules/iam_user_info.py | 1 - plugins/modules/lambda_event.py | 2 -- plugins/modules/route53_health_check.py | 2 -- plugins/modules/route53_info.py | 2 -- plugins/modules/s3_metrics_configuration.py | 2 -- plugins/modules/s3_website.py | 1 - plugins/modules/sns.py | 1 - plugins/modules/sts_session_token.py | 1 - 35 files changed, 1 insertion(+), 55 deletions(-) diff --git a/plugins/modules/aws_config_aggregation_authorization.py b/plugins/modules/aws_config_aggregation_authorization.py index 5a4ee38bf81..e0f4af6f5b4 100644 --- a/plugins/modules/aws_config_aggregation_authorization.py +++ b/plugins/modules/aws_config_aggregation_authorization.py @@ -55,7 +55,6 @@ try: import botocore - from botocore.exceptions import BotoCoreError, ClientError except ImportError: pass # handled by AnsibleAWSModule diff --git a/plugins/modules/aws_config_delivery_channel.py b/plugins/modules/aws_config_delivery_channel.py index f13a0899a20..117afe80c0b 100644 --- a/plugins/modules/aws_config_delivery_channel.py +++ b/plugins/modules/aws_config_delivery_channel.py @@ -68,7 +68,6 @@ try: import botocore - from botocore.exceptions import BotoCoreError, ClientError except ImportError: pass # handled by AnsibleAWSModule diff --git a/plugins/modules/aws_config_recorder.py b/plugins/modules/aws_config_recorder.py index af5de6f938a..e740241c082 100644 --- a/plugins/modules/aws_config_recorder.py +++ b/plugins/modules/aws_config_recorder.py @@ -82,7 +82,6 @@ try: import botocore - from botocore.exceptions import BotoCoreError, ClientError except ImportError: pass # handled by AnsibleAWSModule diff --git a/plugins/modules/aws_config_rule.py b/plugins/modules/aws_config_rule.py index ee606f99e06..0beae0b63a8 100644 --- a/plugins/modules/aws_config_rule.py +++ b/plugins/modules/aws_config_rule.py @@ -110,7 +110,6 @@ try: import botocore - from botocore.exceptions import BotoCoreError, ClientError except ImportError: pass # handled by AnsibleAWSModule diff --git a/plugins/modules/cloudformation_stack_set.py b/plugins/modules/cloudformation_stack_set.py index cda0a2bf9fe..ac7b57bfe9d 100644 --- a/plugins/modules/cloudformation_stack_set.py +++ b/plugins/modules/cloudformation_stack_set.py @@ -302,8 +302,6 @@ import uuid try: - import boto3 - import botocore.exceptions from botocore.exceptions import ClientError, BotoCoreError except ImportError: # handled by AnsibleAWSModule diff --git a/plugins/modules/cloudfront_origin_access_identity.py b/plugins/modules/cloudfront_origin_access_identity.py index 8b98bd99cdb..7370f98625c 100644 --- a/plugins/modules/cloudfront_origin_access_identity.py +++ b/plugins/modules/cloudfront_origin_access_identity.py @@ -121,14 +121,9 @@ ''' import datetime -from functools import partial -import json -import traceback try: - import botocore from botocore.exceptions import ClientError, BotoCoreError - from botocore.signers import CloudFrontSigner except ImportError: pass # caught by imported AnsibleAWSModule diff --git a/plugins/modules/cloudwatchlogs_log_group_metric_filter.py b/plugins/modules/cloudwatchlogs_log_group_metric_filter.py index 0573f8d4f0a..04d0219e48b 100644 --- a/plugins/modules/cloudwatchlogs_log_group_metric_filter.py +++ b/plugins/modules/cloudwatchlogs_log_group_metric_filter.py @@ -101,16 +101,9 @@ """ -try: - from botocore.exceptions import ClientError, BotoCoreError, WaiterError -except ImportError: - pass # caught by AnsibleAWSModule - from ansible.module_utils.common.dict_transformations import camel_dict_to_snake_dict from ansible_collections.amazon.aws.plugins.module_utils.core import AnsibleAWSModule -from ansible_collections.amazon.aws.plugins.module_utils.core import is_boto3_error_code -from ansible_collections.amazon.aws.plugins.module_utils.core import get_boto3_client_method_parameters def metricTransformationHandler(metricTransformations, originMetricTransformations=None): diff --git a/plugins/modules/dynamodb_ttl.py b/plugins/modules/dynamodb_ttl.py index e04dedfafbb..95bf95ffe78 100644 --- a/plugins/modules/dynamodb_ttl.py +++ b/plugins/modules/dynamodb_ttl.py @@ -65,8 +65,6 @@ - { "AttributeName": "deploy_timestamp", "Enabled": true } ''' -import traceback - try: import botocore except ImportError: diff --git a/plugins/modules/ec2_ami_copy.py b/plugins/modules/ec2_ami_copy.py index 531d28726c1..a3a23454b28 100644 --- a/plugins/modules/ec2_ami_copy.py +++ b/plugins/modules/ec2_ami_copy.py @@ -136,7 +136,7 @@ ''' try: - from botocore.exceptions import ClientError, NoCredentialsError, WaiterError, BotoCoreError + from botocore.exceptions import ClientError, WaiterError, BotoCoreError except ImportError: pass # caught by AnsibleAWSModule diff --git a/plugins/modules/ec2_customer_gateway.py b/plugins/modules/ec2_customer_gateway.py index d42fa2b8541..5343b316a4f 100644 --- a/plugins/modules/ec2_customer_gateway.py +++ b/plugins/modules/ec2_customer_gateway.py @@ -110,8 +110,6 @@ ''' try: - from botocore.exceptions import ClientError - import boto3 import botocore except ImportError: pass # Handled by AnsibleAWSModule diff --git a/plugins/modules/ec2_elb.py b/plugins/modules/ec2_elb.py index d9a6231f6b5..f2c124e6e00 100644 --- a/plugins/modules/ec2_elb.py +++ b/plugins/modules/ec2_elb.py @@ -84,7 +84,6 @@ import boto.ec2 import boto.ec2.autoscale import boto.ec2.elb - from boto.regioninfo import RegionInfo except ImportError: pass # Handled by HAS_BOTO diff --git a/plugins/modules/ec2_instance.py b/plugins/modules/ec2_instance.py index ec9e64d7882..a240a350d13 100644 --- a/plugins/modules/ec2_instance.py +++ b/plugins/modules/ec2_instance.py @@ -803,12 +803,10 @@ import uuid try: - import boto3 import botocore.exceptions except ImportError: pass # caught by AnsibleAWSModule -from ansible.module_utils._text import to_bytes from ansible.module_utils._text import to_native from ansible.module_utils.common.dict_transformations import camel_dict_to_snake_dict from ansible.module_utils.common.dict_transformations import snake_dict_to_camel_dict diff --git a/plugins/modules/ec2_instance_info.py b/plugins/modules/ec2_instance_info.py index 5a2244d93c6..be5f1e68892 100644 --- a/plugins/modules/ec2_instance_info.py +++ b/plugins/modules/ec2_instance_info.py @@ -508,10 +508,8 @@ ''' import datetime -import traceback try: - import boto3 import botocore from botocore.exceptions import ClientError except ImportError: diff --git a/plugins/modules/ec2_lc_info.py b/plugins/modules/ec2_lc_info.py index 922274abc46..1a51eb580b3 100644 --- a/plugins/modules/ec2_lc_info.py +++ b/plugins/modules/ec2_lc_info.py @@ -152,7 +152,6 @@ ''' try: - import boto3 import botocore from botocore.exceptions import ClientError except ImportError: diff --git a/plugins/modules/ec2_snapshot_copy.py b/plugins/modules/ec2_snapshot_copy.py index d6aa84a7c04..695d0027d12 100644 --- a/plugins/modules/ec2_snapshot_copy.py +++ b/plugins/modules/ec2_snapshot_copy.py @@ -112,13 +112,11 @@ import traceback try: - import boto3 import botocore from botocore.exceptions import ClientError, WaiterError except ImportError: pass # Handled by AnsibleAWSModule -from ansible.module_utils._text import to_native from ansible.module_utils.common.dict_transformations import camel_dict_to_snake_dict from ansible_collections.amazon.aws.plugins.module_utils.core import AnsibleAWSModule diff --git a/plugins/modules/ec2_vpc_endpoint_info.py b/plugins/modules/ec2_vpc_endpoint_info.py index 4ce142f5733..7e259c6ca8e 100644 --- a/plugins/modules/ec2_vpc_endpoint_info.py +++ b/plugins/modules/ec2_vpc_endpoint_info.py @@ -113,7 +113,6 @@ except ImportError: pass # Handled by AnsibleAWSModule -from ansible.module_utils._text import to_native from ansible.module_utils.common.dict_transformations import camel_dict_to_snake_dict from ansible_collections.amazon.aws.plugins.module_utils.core import AnsibleAWSModule diff --git a/plugins/modules/ec2_vpc_vgw.py b/plugins/modules/ec2_vpc_vgw.py index 2f8702ecace..d54e7264103 100644 --- a/plugins/modules/ec2_vpc_vgw.py +++ b/plugins/modules/ec2_vpc_vgw.py @@ -116,7 +116,6 @@ try: import botocore - import boto3 except ImportError: pass # Handled by AnsibleAWSModule diff --git a/plugins/modules/ecs_attribute.py b/plugins/modules/ecs_attribute.py index 552747ba10c..be9210f3272 100644 --- a/plugins/modules/ecs_attribute.py +++ b/plugins/modules/ecs_attribute.py @@ -111,7 +111,6 @@ ''' try: - import boto3 import botocore from botocore.exceptions import ClientError, EndpointConnectionError except ImportError: diff --git a/plugins/modules/ecs_cluster.py b/plugins/modules/ecs_cluster.py index 0cc51065a7a..87e0476be9b 100644 --- a/plugins/modules/ecs_cluster.py +++ b/plugins/modules/ecs_cluster.py @@ -107,7 +107,6 @@ import time try: - import boto3 import botocore except ImportError: pass # Handled by AnsibleAWSModule diff --git a/plugins/modules/ecs_taskdefinition.py b/plugins/modules/ecs_taskdefinition.py index 33fa0203dda..ed2825d0942 100644 --- a/plugins/modules/ecs_taskdefinition.py +++ b/plugins/modules/ecs_taskdefinition.py @@ -214,7 +214,6 @@ pass # caught by AnsibleAWSModule from ansible.module_utils._text import to_text -from ansible.module_utils.common.dict_transformations import camel_dict_to_snake_dict from ansible_collections.amazon.aws.plugins.module_utils.core import AnsibleAWSModule diff --git a/plugins/modules/elasticache_parameter_group.py b/plugins/modules/elasticache_parameter_group.py index 52f77da267d..00992a91e51 100644 --- a/plugins/modules/elasticache_parameter_group.py +++ b/plugins/modules/elasticache_parameter_group.py @@ -108,7 +108,6 @@ import traceback try: - import boto3 import botocore except ImportError: pass # Handled by AnsibleAWSModule diff --git a/plugins/modules/elb_application_lb_info.py b/plugins/modules/elb_application_lb_info.py index f3580dee58b..14937befba8 100644 --- a/plugins/modules/elb_application_lb_info.py +++ b/plugins/modules/elb_application_lb_info.py @@ -165,7 +165,6 @@ import traceback try: - import boto3 import botocore from botocore.exceptions import ClientError, NoCredentialsError except ImportError: diff --git a/plugins/modules/elb_instance.py b/plugins/modules/elb_instance.py index fe10d6cd8dc..97682acb659 100644 --- a/plugins/modules/elb_instance.py +++ b/plugins/modules/elb_instance.py @@ -90,7 +90,6 @@ import boto.ec2 import boto.ec2.autoscale import boto.ec2.elb - from boto.regioninfo import RegionInfo except ImportError: pass # Handled by HAS_BOTO diff --git a/plugins/modules/elb_target.py b/plugins/modules/elb_target.py index 4f81611fd2e..31761953b17 100644 --- a/plugins/modules/elb_target.py +++ b/plugins/modules/elb_target.py @@ -115,7 +115,6 @@ import traceback try: - import boto3 import botocore from botocore.exceptions import ClientError, BotoCoreError except ImportError: diff --git a/plugins/modules/elb_target_group_info.py b/plugins/modules/elb_target_group_info.py index 16d5816afc0..00cc425e0de 100644 --- a/plugins/modules/elb_target_group_info.py +++ b/plugins/modules/elb_target_group_info.py @@ -210,7 +210,6 @@ import traceback try: - import boto3 import botocore from botocore.exceptions import ClientError, NoCredentialsError except ImportError: diff --git a/plugins/modules/iam_mfa_device_info.py b/plugins/modules/iam_mfa_device_info.py index 52f183edf15..e86687134a9 100644 --- a/plugins/modules/iam_mfa_device_info.py +++ b/plugins/modules/iam_mfa_device_info.py @@ -61,7 +61,6 @@ ''' try: - import boto3 import botocore from botocore.exceptions import ClientError except ImportError: diff --git a/plugins/modules/iam_server_certificate_info.py b/plugins/modules/iam_server_certificate_info.py index 6e37185680f..994344147e4 100644 --- a/plugins/modules/iam_server_certificate_info.py +++ b/plugins/modules/iam_server_certificate_info.py @@ -80,7 +80,6 @@ try: - import boto3 import botocore import botocore.exceptions except ImportError: diff --git a/plugins/modules/iam_user_info.py b/plugins/modules/iam_user_info.py index 00c9368dc37..f6aaa842eef 100644 --- a/plugins/modules/iam_user_info.py +++ b/plugins/modules/iam_user_info.py @@ -102,7 +102,6 @@ ''' try: - import botocore from botocore.exceptions import BotoCoreError, ClientError except ImportError: pass # caught by AnsibleAWSModule diff --git a/plugins/modules/lambda_event.py b/plugins/modules/lambda_event.py index 26365d78407..3906771255f 100644 --- a/plugins/modules/lambda_event.py +++ b/plugins/modules/lambda_event.py @@ -115,10 +115,8 @@ ''' import re -import sys try: - import boto3 from botocore.exceptions import ClientError, ParamValidationError, MissingParametersError except ImportError: pass # Handled by AnsibleAWSModule diff --git a/plugins/modules/route53_health_check.py b/plugins/modules/route53_health_check.py index 3cd441c42a0..03ac8b09af0 100644 --- a/plugins/modules/route53_health_check.py +++ b/plugins/modules/route53_health_check.py @@ -118,9 +118,7 @@ import uuid try: - import boto import boto.ec2 - from boto import route53 from boto.route53 import Route53Connection, exception from boto.route53.healthcheck import HealthCheck except ImportError: diff --git a/plugins/modules/route53_info.py b/plugins/modules/route53_info.py index d2e173749ba..e9018a914f9 100644 --- a/plugins/modules/route53_info.py +++ b/plugins/modules/route53_info.py @@ -206,9 +206,7 @@ ''' try: - import boto import botocore - import boto3 except ImportError: pass # Handled by HAS_BOTO and HAS_BOTO3 diff --git a/plugins/modules/s3_metrics_configuration.py b/plugins/modules/s3_metrics_configuration.py index e99f414fcc5..2480d1d7560 100644 --- a/plugins/modules/s3_metrics_configuration.py +++ b/plugins/modules/s3_metrics_configuration.py @@ -95,8 +95,6 @@ ''' try: - import boto3 - import botocore from botocore.exceptions import ClientError, BotoCoreError except ImportError: pass # Handled by AnsibleAWSModule diff --git a/plugins/modules/s3_website.py b/plugins/modules/s3_website.py index 31071265f92..8b93edb5bb7 100644 --- a/plugins/modules/s3_website.py +++ b/plugins/modules/s3_website.py @@ -162,7 +162,6 @@ import time try: - import boto3 import botocore from botocore.exceptions import ClientError, ParamValidationError except ImportError: diff --git a/plugins/modules/sns.py b/plugins/modules/sns.py index 49b73aa68f4..2840ddd2ac9 100644 --- a/plugins/modules/sns.py +++ b/plugins/modules/sns.py @@ -131,7 +131,6 @@ """ import json -import traceback try: from botocore.exceptions import BotoCoreError, ClientError diff --git a/plugins/modules/sts_session_token.py b/plugins/modules/sts_session_token.py index 4183b976d15..7c8221a9c68 100644 --- a/plugins/modules/sts_session_token.py +++ b/plugins/modules/sts_session_token.py @@ -80,7 +80,6 @@ ''' try: - import boto3 import botocore from botocore.exceptions import ClientError except ImportError: From 90965c5fcf97e818c63783d7e80cb180932e090c Mon Sep 17 00:00:00 2001 From: Mark Chappell Date: Fri, 15 Jan 2021 17:35:49 +0100 Subject: [PATCH 4/5] Route53 Info was migrated to Boto3 drop the HAS_BOTO check --- plugins/modules/route53_info.py | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/plugins/modules/route53_info.py b/plugins/modules/route53_info.py index e9018a914f9..abdf7e44709 100644 --- a/plugins/modules/route53_info.py +++ b/plugins/modules/route53_info.py @@ -208,13 +208,11 @@ try: import botocore except ImportError: - pass # Handled by HAS_BOTO and HAS_BOTO3 + pass # Handled by AnsibleAWSModule from ansible.module_utils._text import to_native from ansible_collections.amazon.aws.plugins.module_utils.core import AnsibleAWSModule -from ansible_collections.amazon.aws.plugins.module_utils.ec2 import HAS_BOTO -from ansible_collections.amazon.aws.plugins.module_utils.ec2 import HAS_BOTO3 def get_hosted_zone(client, module): @@ -460,10 +458,6 @@ def main(): if module._name == 'route53_facts': module.deprecate("The 'route53_facts' module has been renamed to 'route53_info'", date='2021-12-01', collection_name='community.aws') - # Validate Requirements - if not (HAS_BOTO or HAS_BOTO3): - module.fail_json(msg='json and boto/boto3 is required.') - try: route53 = module.client('route53') except (botocore.exceptions.ClientError, botocore.exceptions.BotoCoreError) as e: From 897d3688700bf6f32f150d41db681bdaedc4ae90 Mon Sep 17 00:00:00 2001 From: Mark Chappell Date: Fri, 15 Jan 2021 20:10:16 +0100 Subject: [PATCH 5/5] changelog --- changelogs/fragments/360-imports-cleanup.yml | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 changelogs/fragments/360-imports-cleanup.yml diff --git a/changelogs/fragments/360-imports-cleanup.yml b/changelogs/fragments/360-imports-cleanup.yml new file mode 100644 index 00000000000..dae43e8d1ec --- /dev/null +++ b/changelogs/fragments/360-imports-cleanup.yml @@ -0,0 +1,2 @@ +minor_changes: +- various community.aws modules - cleanup of Python imports (https://github.com/ansible-collections/community.aws/pull/360).