From c655e785ab440342d23ea35c7d2031416d6fc290 Mon Sep 17 00:00:00 2001 From: Mark Chappell Date: Sat, 10 Apr 2021 09:55:59 +0200 Subject: [PATCH 1/3] Use shared normalize_boto3_result code --- plugins/modules/ec2_vpc_peering_info.py | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/plugins/modules/ec2_vpc_peering_info.py b/plugins/modules/ec2_vpc_peering_info.py index a086fde3639..92b2e1e8bd9 100644 --- a/plugins/modules/ec2_vpc_peering_info.py +++ b/plugins/modules/ec2_vpc_peering_info.py @@ -208,26 +208,23 @@ except ImportError: 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 normalize_boto3_result 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_filter_list from ansible_collections.amazon.aws.plugins.module_utils.ec2 import camel_dict_to_snake_dict -def date_handler(obj): - return obj.isoformat() if hasattr(obj, 'isoformat') else obj - - def get_vpc_peers(client, module): params = dict() params['Filters'] = ansible_dict_to_boto3_filter_list(module.params.get('filters')) if module.params.get('peer_connection_ids'): params['VpcPeeringConnectionIds'] = module.params.get('peer_connection_ids') try: - result = json.loads(json.dumps(client.describe_vpc_peering_connections(**params), default=date_handler)) - except Exception as e: - module.fail_json(msg=to_native(e)) + result = client.describe_vpc_peering_connections(**params) + result = normalize_boto3_result(result) + except (botocore.exceptions.ClientError, botocore.exceptions.BotoCoreError) as e: + module.fail_json_aws(e, msg="Failed to describe peering connections") return result['VpcPeeringConnections'] From 56f92df8b423effd0cc74208d6232e9a59584e93 Mon Sep 17 00:00:00 2001 From: Mark Chappell Date: Sat, 10 Apr 2021 09:57:45 +0200 Subject: [PATCH 2/3] Add Retries --- plugins/modules/ec2_vpc_peering_info.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/plugins/modules/ec2_vpc_peering_info.py b/plugins/modules/ec2_vpc_peering_info.py index 92b2e1e8bd9..5f3cb435de3 100644 --- a/plugins/modules/ec2_vpc_peering_info.py +++ b/plugins/modules/ec2_vpc_peering_info.py @@ -210,6 +210,7 @@ from ansible_collections.amazon.aws.plugins.module_utils.core import AnsibleAWSModule from ansible_collections.amazon.aws.plugins.module_utils.core import normalize_boto3_result +from ansible_collections.amazon.aws.plugins.module_utils.ec2 import AWSRetry 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_filter_list from ansible_collections.amazon.aws.plugins.module_utils.ec2 import camel_dict_to_snake_dict @@ -221,7 +222,7 @@ def get_vpc_peers(client, module): if module.params.get('peer_connection_ids'): params['VpcPeeringConnectionIds'] = module.params.get('peer_connection_ids') try: - result = client.describe_vpc_peering_connections(**params) + result = client.describe_vpc_peering_connections(aws_retry=True, **params) result = normalize_boto3_result(result) except (botocore.exceptions.ClientError, botocore.exceptions.BotoCoreError) as e: module.fail_json_aws(e, msg="Failed to describe peering connections") @@ -241,7 +242,7 @@ def main(): 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') + 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') From 9f1dd2a58fc3edc855ba1600039cd9a5c8afd8b4 Mon Sep 17 00:00:00 2001 From: Mark Chappell Date: Sat, 10 Apr 2021 10:00:01 +0200 Subject: [PATCH 3/3] Add changelog --- changelogs/fragments/536-ec2_vpc_peering_info-retry.yml | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 changelogs/fragments/536-ec2_vpc_peering_info-retry.yml diff --git a/changelogs/fragments/536-ec2_vpc_peering_info-retry.yml b/changelogs/fragments/536-ec2_vpc_peering_info-retry.yml new file mode 100644 index 00000000000..87522621acf --- /dev/null +++ b/changelogs/fragments/536-ec2_vpc_peering_info-retry.yml @@ -0,0 +1,2 @@ +minor_changes: +- ec2_vpc_peering_info - add retries on common AWS failures (https://github.com/ansible-collections/community.aws/pull/536).