Skip to content

Commit

Permalink
ec2_instance_info - Add AWS Retries (ansible-collections#521)
Browse files Browse the repository at this point in the history
* Add retries to ec2_instance_info

* changelog
  • Loading branch information
tremble authored and jillr committed Apr 6, 2021
1 parent 6609c6d commit 82d2ad3
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions plugins/modules/ec2_instance_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -511,27 +511,32 @@

try:
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 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 boto3_tag_list_to_ansible_dict


@AWSRetry.jittered_backoff()
def _describe_instances(connection, **params):
paginator = connection.get_paginator('describe_instances')
return paginator.paginate(**params).build_full_result()


def list_ec2_instances(connection, module):

instance_ids = module.params.get("instance_ids")
uptime = module.params.get('minimum_uptime')
filters = ansible_dict_to_boto3_filter_list(module.params.get("filters"))

try:
reservations_paginator = connection.get_paginator('describe_instances')
reservations = reservations_paginator.paginate(InstanceIds=instance_ids, Filters=filters).build_full_result()
except ClientError as e:
reservations = _describe_instances(connection, InstanceIds=instance_ids, Filters=filters)
except (botocore.exceptions.ClientError, botocore.exceptions.BotoCoreError) as e:
module.fail_json_aws(e, msg="Failed to list ec2 instances")

instances = []
Expand Down

0 comments on commit 82d2ad3

Please sign in to comment.