From 130cf3cc5980014020632f19fdab79c9bcf28add Mon Sep 17 00:00:00 2001 From: Mark Chappell Date: Sat, 16 Jan 2021 10:50:49 +0100 Subject: [PATCH] Bulk import cleanup (#360) * Split imports and reorder * Import camel_dict_to_snake_dict and snake_dict_to_camel_dict direct from ansible.module_utils.common.dict_transformations * Remove unused imports * Route53 Info was migrated to Boto3 drop the HAS_BOTO check and import * changelog --- changelogs/fragments/360-imports-cleanup.yml | 2 ++ .../aws_config_aggregation_authorization.py | 1 - .../modules/aws_config_delivery_channel.py | 8 +++++--- plugins/modules/aws_config_recorder.py | 8 +++++--- plugins/modules/aws_config_rule.py | 8 +++++--- plugins/modules/cloudformation_stack_set.py | 19 +++++++++---------- .../cloudfront_origin_access_identity.py | 13 +++++-------- .../cloudwatchlogs_log_group_metric_filter.py | 9 +++------ plugins/modules/dynamodb_ttl.py | 2 -- plugins/modules/ec2_ami_copy.py | 13 +++++++------ plugins/modules/ec2_customer_gateway.py | 5 ++--- plugins/modules/ec2_elb.py | 1 - plugins/modules/ec2_instance.py | 16 +++++++--------- plugins/modules/ec2_instance_info.py | 6 ++---- plugins/modules/ec2_lc_info.py | 4 ++-- plugins/modules/ec2_snapshot_copy.py | 4 +--- plugins/modules/ec2_vpc_endpoint_info.py | 6 +++--- plugins/modules/ec2_vpc_vgw.py | 1 - plugins/modules/ecs_attribute.py | 1 - plugins/modules/ecs_cluster.py | 2 +- plugins/modules/ecs_taskdefinition.py | 4 ++-- .../modules/elasticache_parameter_group.py | 4 +--- plugins/modules/elb_application_lb_info.py | 4 ++-- plugins/modules/elb_instance.py | 1 - plugins/modules/elb_target.py | 5 ++--- plugins/modules/elb_target_group_info.py | 4 ++-- plugins/modules/iam_mfa_device_info.py | 4 ++-- .../modules/iam_server_certificate_info.py | 1 - plugins/modules/iam_user_info.py | 9 +++++---- plugins/modules/lambda_event.py | 5 ++--- plugins/modules/route53_health_check.py | 5 +---- plugins/modules/route53_info.py | 11 ++--------- plugins/modules/s3_metrics_configuration.py | 8 ++++---- plugins/modules/s3_website.py | 4 ++-- plugins/modules/sns.py | 1 - plugins/modules/sts_session_token.py | 1 - 36 files changed, 86 insertions(+), 114 deletions(-) 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). 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 6e7fe5b2fa9..117afe80c0b 100644 --- a/plugins/modules/aws_config_delivery_channel.py +++ b/plugins/modules/aws_config_delivery_channel.py @@ -68,12 +68,14 @@ try: import botocore - from botocore.exceptions import BotoCoreError, ClientError 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.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 # 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..e740241c082 100644 --- a/plugins/modules/aws_config_recorder.py +++ b/plugins/modules/aws_config_recorder.py @@ -82,12 +82,14 @@ try: import botocore - from botocore.exceptions import BotoCoreError, ClientError 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.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 def resource_exists(client, module, params): diff --git a/plugins/modules/aws_config_rule.py b/plugins/modules/aws_config_rule.py index 80550586aa8..0beae0b63a8 100644 --- a/plugins/modules/aws_config_rule.py +++ b/plugins/modules/aws_config_rule.py @@ -110,12 +110,14 @@ try: import botocore - from botocore.exceptions import BotoCoreError, ClientError 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.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 def rule_exists(client, module, params): diff --git a/plugins/modules/cloudformation_stack_set.py b/plugins/modules/cloudformation_stack_set.py index 148cbe61047..ac7b57bfe9d 100644 --- a/plugins/modules/cloudformation_stack_set.py +++ b/plugins/modules/cloudformation_stack_set.py @@ -296,26 +296,25 @@ ''' # NOQA -import time import datetime -import uuid import itertools +import time +import uuid try: - import boto3 - import botocore.exceptions from botocore.exceptions import ClientError, BotoCoreError except ImportError: # 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.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 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 00f188222c5..7370f98625c 100644 --- a/plugins/modules/cloudfront_origin_access_identity.py +++ b/plugins/modules/cloudfront_origin_access_identity.py @@ -120,21 +120,18 @@ ''' -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 -import traceback try: - import botocore - from botocore.signers import CloudFrontSigner from botocore.exceptions import ClientError, BotoCoreError 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 + 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..04d0219e48b 100644 --- a/plugins/modules/cloudwatchlogs_log_group_metric_filter.py +++ b/plugins/modules/cloudwatchlogs_log_group_metric_filter.py @@ -100,13 +100,10 @@ ] """ -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.module_utils.common.dict_transformations import camel_dict_to_snake_dict + +from ansible_collections.amazon.aws.plugins.module_utils.core import AnsibleAWSModule 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 38f1123168f..a3a23454b28 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 + from botocore.exceptions import ClientError, WaiterError, BotoCoreError except ImportError: 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 ansible_dict_to_boto3_tag_list + def copy_image(module, ec2): """ diff --git a/plugins/modules/ec2_customer_gateway.py b/plugins/modules/ec2_customer_gateway.py index 1e9fc1ded47..5343b316a4f 100644 --- a/plugins/modules/ec2_customer_gateway.py +++ b/plugins/modules/ec2_customer_gateway.py @@ -110,15 +110,14 @@ ''' try: - from botocore.exceptions import ClientError - import boto3 import botocore 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_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 aba7ac26b10..a240a350d13 100644 --- a/plugins/modules/ec2_instance.py +++ b/plugins/modules/ec2_instance.py @@ -795,32 +795,30 @@ 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 import botocore.exceptions except ImportError: 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.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 -from ansible.module_utils._text import to_bytes -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 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 camel_dict_to_snake_dict -from ansible_collections.amazon.aws.plugins.module_utils.ec2 import snake_dict_to_camel_dict +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 compare_aws_tags module = None diff --git a/plugins/modules/ec2_instance_info.py b/plugins/modules/ec2_instance_info.py index e37f2cf9cd1..be5f1e68892 100644 --- a/plugins/modules/ec2_instance_info.py +++ b/plugins/modules/ec2_instance_info.py @@ -507,21 +507,19 @@ sample: vpc-0011223344 ''' -import traceback import datetime - try: - import boto3 import botocore from botocore.exceptions import ClientError 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..1a51eb580b3 100644 --- a/plugins/modules/ec2_lc_info.py +++ b/plugins/modules/ec2_lc_info.py @@ -152,14 +152,14 @@ ''' try: - import boto3 import botocore from botocore.exceptions import ClientError 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..695d0027d12 100644 --- a/plugins/modules/ec2_snapshot_copy.py +++ b/plugins/modules/ec2_snapshot_copy.py @@ -112,16 +112,14 @@ 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 -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 e72b487db3d..7e259c6ca8e 100644 --- a/plugins/modules/ec2_vpc_endpoint_info.py +++ b/plugins/modules/ec2_vpc_endpoint_info.py @@ -113,11 +113,11 @@ 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 -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 +from ansible_collections.amazon.aws.plugins.module_utils.ec2 import ansible_dict_to_boto3_filter_list def date_handler(obj): 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 ed0dc1c78ff..87e0476be9b 100644 --- a/plugins/modules/ecs_cluster.py +++ b/plugins/modules/ecs_cluster.py @@ -103,10 +103,10 @@ type: str sample: ACTIVE ''' + 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 6158fb4ec21..ed2825d0942 100644 --- a/plugins/modules/ecs_taskdefinition.py +++ b/plugins/modules/ecs_taskdefinition.py @@ -213,10 +213,10 @@ 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 camel_dict_to_snake_dict from ansible.module_utils._text import to_text +from ansible_collections.amazon.aws.plugins.module_utils.core import AnsibleAWSModule + class EcsTaskManager: """Handles ECS Tasks""" diff --git a/plugins/modules/elasticache_parameter_group.py b/plugins/modules/elasticache_parameter_group.py index 1e9c574178d..00992a91e51 100644 --- a/plugins/modules/elasticache_parameter_group.py +++ b/plugins/modules/elasticache_parameter_group.py @@ -108,17 +108,15 @@ import traceback try: - import boto3 import botocore except ImportError: 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 -# 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 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 06e1f3ae229..14937befba8 100644 --- a/plugins/modules/elb_application_lb_info.py +++ b/plugins/modules/elb_application_lb_info.py @@ -165,17 +165,17 @@ import traceback try: - import boto3 import botocore from botocore.exceptions import ClientError, NoCredentialsError 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 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_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 b8cda233814..31761953b17 100644 --- a/plugins/modules/elb_target.py +++ b/plugins/modules/elb_target.py @@ -111,20 +111,19 @@ ''' -import traceback from time import time, sleep +import traceback try: - import boto3 import botocore from botocore.exceptions import ClientError, BotoCoreError 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 -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 diff --git a/plugins/modules/elb_target_group_info.py b/plugins/modules/elb_target_group_info.py index a9694428872..00cc425e0de 100644 --- a/plugins/modules/elb_target_group_info.py +++ b/plugins/modules/elb_target_group_info.py @@ -210,17 +210,17 @@ import traceback try: - import boto3 import botocore from botocore.exceptions import ClientError, NoCredentialsError 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 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..e86687134a9 100644 --- a/plugins/modules/iam_mfa_device_info.py +++ b/plugins/modules/iam_mfa_device_info.py @@ -61,14 +61,14 @@ ''' try: - import boto3 import botocore from botocore.exceptions import ClientError 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_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 8e1856b1763..f6aaa842eef 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.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 + @AWSRetry.exponential_backoff() def list_iam_users_with_backoff(client, operation, **kwargs): diff --git a/plugins/modules/lambda_event.py b/plugins/modules/lambda_event.py index e0009d13582..3906771255f 100644 --- a/plugins/modules/lambda_event.py +++ b/plugins/modules/lambda_event.py @@ -115,17 +115,16 @@ ''' import re -import sys try: - import boto3 from botocore.exceptions import ClientError, ParamValidationError, MissingParametersError 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/route53_health_check.py b/plugins/modules/route53_health_check.py index a1f9c9a268c..03ac8b09af0 100644 --- a/plugins/modules/route53_health_check.py +++ b/plugins/modules/route53_health_check.py @@ -118,18 +118,15 @@ 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: 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..abdf7e44709 100644 --- a/plugins/modules/route53_info.py +++ b/plugins/modules/route53_info.py @@ -204,18 +204,15 @@ start_record_name: "host1.workshop.test.io" register: RECORDS ''' + try: - import boto import botocore - import boto3 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): @@ -461,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: diff --git a/plugins/modules/s3_metrics_configuration.py b/plugins/modules/s3_metrics_configuration.py index 729503cf88b..2480d1d7560 100644 --- a/plugins/modules/s3_metrics_configuration.py +++ b/plugins/modules/s3_metrics_configuration.py @@ -95,14 +95,14 @@ ''' try: - import boto3 - import botocore from botocore.exceptions import ClientError, BotoCoreError 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): diff --git a/plugins/modules/s3_website.py b/plugins/modules/s3_website.py index 6f7aa898391..8b93edb5bb7 100644 --- a/plugins/modules/s3_website.py +++ b/plugins/modules/s3_website.py @@ -162,15 +162,15 @@ import time try: - import boto3 import botocore from botocore.exceptions import ClientError, ParamValidationError 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): 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: