From 2043aad582404829e0ce29fd5de85b45be3ca136 Mon Sep 17 00:00:00 2001 From: Brian Scholer Date: Wed, 17 Oct 2018 12:34:37 -0400 Subject: [PATCH] [aws] ec2_instance: don't report changed when instance is already stopped (#46714) --- lib/ansible/modules/cloud/amazon/ec2_instance.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/ansible/modules/cloud/amazon/ec2_instance.py b/lib/ansible/modules/cloud/amazon/ec2_instance.py index c6db3e9a581..1604a3d81ab 100644 --- a/lib/ansible/modules/cloud/amazon/ec2_instance.py +++ b/lib/ansible/modules/cloud/amazon/ec2_instance.py @@ -1343,7 +1343,7 @@ def change_instance_state(filters, desired_state, ec2=None): changed = set() instances = find_instances(ec2, filters=filters) - to_change = set(i['InstanceId'] for i in instances) + to_change = set(i['InstanceId'] for i in instances if i['State']['Name'].upper() != desired_state) unchanged = set() for inst in instances: @@ -1358,7 +1358,7 @@ def change_instance_state(filters, desired_state, ec2=None): resp = ec2.terminate_instances(InstanceIds=[inst['InstanceId']]) [changed.add(i['InstanceId']) for i in resp['TerminatingInstances']] if desired_state == 'STOPPED': - if inst['State']['Name'] == 'stopping': + if inst['State']['Name'] in ('stopping', 'stopped'): unchanged.add(inst['InstanceId']) continue @@ -1383,7 +1383,7 @@ def change_instance_state(filters, desired_state, ec2=None): await_instances(ids=list(changed) + list(unchanged), state=desired_state) change_failed = list(to_change - changed) - instances = find_instances(ec2, ids=list(to_change)) + instances = find_instances(ec2, ids=list(i['InstanceId'] for i in instances)) return changed, change_failed, instances