From b0f124b3ba8426ba981177b7fe14ee8abf0c69d9 Mon Sep 17 00:00:00 2001 From: Maxime de Roucy Date: Sun, 15 Oct 2023 13:20:53 +0200 Subject: [PATCH] add InvalidInstanceID.NotFound to the list of error codes that should trigger a retry (catch_extra_error_codes) --- .../fragments/1650-fix-invalidinstanceid-notfound.yml | 2 +- plugins/modules/ec2_instance.py | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/changelogs/fragments/1650-fix-invalidinstanceid-notfound.yml b/changelogs/fragments/1650-fix-invalidinstanceid-notfound.yml index 7ffe218892..8953b2390a 100644 --- a/changelogs/fragments/1650-fix-invalidinstanceid-notfound.yml +++ b/changelogs/fragments/1650-fix-invalidinstanceid-notfound.yml @@ -1,3 +1,3 @@ --- bugfixes: - - ec2_instance - retry API call if we get ``InvalidGroup.NotFound`` error (https://github.com/ansible-collections/amazon.aws/pull/1650). + - ec2_instance - retry API call if we get ``InvalidInstanceID.NotFound`` error (https://github.com/ansible-collections/amazon.aws/pull/1650). diff --git a/plugins/modules/ec2_instance.py b/plugins/modules/ec2_instance.py index d1f86b54f4..0b468333e6 100644 --- a/plugins/modules/ec2_instance.py +++ b/plugins/modules/ec2_instance.py @@ -1950,7 +1950,12 @@ def ensure_present(existing_matches, desired_module_state, current_count=None): for ins in instances: # Wait for instances to exist (don't check state) try: - client.describe_instance_status(InstanceIds=[ins["InstanceId"]], IncludeAllInstances=True) + AWSRetry.jittered_backoff( + catch_extra_error_codes=["InvalidInstanceID.NotFound"], + )(client.describe_instance_status)( + InstanceIds=[ins["InstanceId"]], + IncludeAllInstances=True, + ) except (botocore.exceptions.BotoCoreError, botocore.exceptions.ClientError) as e: module.fail_json_aws(e, msg="Failed to fetch status of new EC2 instance") changes = diff_instance_and_params(ins, module.params, skip=["UserData", "EbsOptimized"])