From 8b64555eceba54417b63b8fcec683f3d2048c5f5 Mon Sep 17 00:00:00 2001 From: Stefan Horning Date: Fri, 20 Nov 2020 12:36:06 +0100 Subject: [PATCH 1/2] Don't hardcode max_attempts, as it leads to errors when AMI builds long and timeout setting won't have any effect. --- changelogs/fragments/194-ec2-ami-max-attempts.yaml | 3 +++ plugins/modules/ec2_ami.py | 10 +++++----- 2 files changed, 8 insertions(+), 5 deletions(-) create mode 100644 changelogs/fragments/194-ec2-ami-max-attempts.yaml diff --git a/changelogs/fragments/194-ec2-ami-max-attempts.yaml b/changelogs/fragments/194-ec2-ami-max-attempts.yaml new file mode 100644 index 00000000000..f160f6d4be2 --- /dev/null +++ b/changelogs/fragments/194-ec2-ami-max-attempts.yaml @@ -0,0 +1,3 @@ +--- +minor_changes: + - ec2_ami - fixed and streamlined max_attempts logic when waiting for AMIs to finish and increased wait_timeout to 1200 for a more reliably module run. diff --git a/plugins/modules/ec2_ami.py b/plugins/modules/ec2_ami.py index 59fc209f2bc..65372363c9f 100644 --- a/plugins/modules/ec2_ami.py +++ b/plugins/modules/ec2_ami.py @@ -48,7 +48,7 @@ wait_timeout: description: - How long before wait gives up, in seconds. - default: 900 + default: 1200 type: int state: description: @@ -505,9 +505,9 @@ def create_image(module, connection): module.fail_json_aws(e, msg="Error registering image") if wait: - waiter = get_waiter(connection, 'image_available') - delay = wait_timeout // 30 - max_attempts = 30 + delay = 15 + max_attempts = wait_timeout // delay + waiter = connection.get_waiter('image_available') waiter.wait(ImageIds=[image_id], WaiterConfig=dict(Delay=delay, MaxAttempts=max_attempts)) if tags: @@ -718,7 +718,7 @@ def main(): delete_snapshot=dict(default=False, type='bool'), name=dict(), wait=dict(type='bool', default=False), - wait_timeout=dict(default=900, type='int'), + wait_timeout=dict(default=1200, type='int'), description=dict(default=''), no_reboot=dict(default=False, type='bool'), state=dict(default='present', choices=['present', 'absent']), From 1f4bb32c4b7c06cbb952a1f760245d7b491bf418 Mon Sep 17 00:00:00 2001 From: Stefan Horning Date: Fri, 20 Nov 2020 12:39:21 +0100 Subject: [PATCH 2/2] Fix after rebase --- plugins/modules/ec2_ami.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/modules/ec2_ami.py b/plugins/modules/ec2_ami.py index 65372363c9f..86364f78066 100644 --- a/plugins/modules/ec2_ami.py +++ b/plugins/modules/ec2_ami.py @@ -507,7 +507,7 @@ def create_image(module, connection): if wait: delay = 15 max_attempts = wait_timeout // delay - waiter = connection.get_waiter('image_available') + waiter = get_waiter(connection, 'image_available') waiter.wait(ImageIds=[image_id], WaiterConfig=dict(Delay=delay, MaxAttempts=max_attempts)) if tags: