From f916dae700e42e423da2198965fb7c01b3828750 Mon Sep 17 00:00:00 2001 From: Christopher Kotfila Date: Tue, 13 Sep 2016 15:07:14 -0400 Subject: [PATCH] Unpack AWS reservations while waiting to terminate (#4012) Previously calculation of the number of instances that have been terminated assumed all instances were in the first reservation returned by AWS. If this is not the case the calculated number of instances terminated never reaches the number of instances and the module always times out. By unpacking the instances we get an accurate number and the module correctly exits. --- lib/ansible/modules/cloud/amazon/ec2.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/ansible/modules/cloud/amazon/ec2.py b/lib/ansible/modules/cloud/amazon/ec2.py index 72b3d7686c..c8649f3d3d 100755 --- a/lib/ansible/modules/cloud/amazon/ec2.py +++ b/lib/ansible/modules/cloud/amazon/ec2.py @@ -1233,7 +1233,7 @@ def terminate_instances(module, ec2, instance_ids): instance_ids=terminated_instance_ids, \ filters={'instance-state-name':'terminated'}) try: - num_terminated = len(response.pop().instances) + num_terminated = sum([len(res.instances) for res in response]) except Exception as e: # got a bad response of some sort, possibly due to # stale/cached data. Wait a second and then try again