Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PR #928/524129fc backport][stable-4] ec2_instance - expand use of AWSRetry #931

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions changelogs/fragments/927-ec2_instance-retries.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
minor_changes:
- ec2_instance - expanded the use of the automatic retries on temporary failures (https://github.com/ansible-collections/amazon.aws/issues/927).
10 changes: 6 additions & 4 deletions plugins/modules/ec2_instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -1855,9 +1855,11 @@ def enforce_count(existing_matches, module, desired_module_state):
module.exit_json(changed=True, msg='Would have terminated following instances if not in check mode {0}'.format(terminate_ids))
# terminate instances
try:
result = client.terminate_instances(InstanceIds=terminate_ids)
result = client.terminate_instances(aws_retry=True, InstanceIds=terminate_ids)
await_instances(terminate_ids, desired_module_state='terminated', force_wait=True)
except botocore.exceptions.ClientError as e:
except is_boto3_error_code('InvalidInstanceID.NotFound'):
pass
except botocore.exceptions.ClientError as e: # pylint: disable=duplicate-except
module.fail_json(e, msg='Unable to terminate instances')
module.exit_json(
changed=True,
Expand Down Expand Up @@ -1933,12 +1935,12 @@ def ensure_present(existing_matches, desired_module_state):

def run_instances(**instance_spec):
try:
return client.run_instances(**instance_spec)
return client.run_instances(aws_retry=True, **instance_spec)
except is_boto3_error_message('Invalid IAM Instance Profile ARN'):
# If the instance profile has just been created, it takes some time to be visible by ec2
# So we wait 10 second and retry the run_instances
time.sleep(10)
return client.run_instances(**instance_spec)
return client.run_instances(aws_retry=True, **instance_spec)


def build_filters():
Expand Down