mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
[aws] ec2_instance: don't report changed when instance is already stopped (#46714)
This commit is contained in:
parent
e744c83808
commit
2043aad582
1 changed files with 3 additions and 3 deletions
|
@ -1343,7 +1343,7 @@ def change_instance_state(filters, desired_state, ec2=None):
|
||||||
|
|
||||||
changed = set()
|
changed = set()
|
||||||
instances = find_instances(ec2, filters=filters)
|
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()
|
unchanged = set()
|
||||||
|
|
||||||
for inst in instances:
|
for inst in instances:
|
||||||
|
@ -1358,7 +1358,7 @@ def change_instance_state(filters, desired_state, ec2=None):
|
||||||
resp = ec2.terminate_instances(InstanceIds=[inst['InstanceId']])
|
resp = ec2.terminate_instances(InstanceIds=[inst['InstanceId']])
|
||||||
[changed.add(i['InstanceId']) for i in resp['TerminatingInstances']]
|
[changed.add(i['InstanceId']) for i in resp['TerminatingInstances']]
|
||||||
if desired_state == 'STOPPED':
|
if desired_state == 'STOPPED':
|
||||||
if inst['State']['Name'] == 'stopping':
|
if inst['State']['Name'] in ('stopping', 'stopped'):
|
||||||
unchanged.add(inst['InstanceId'])
|
unchanged.add(inst['InstanceId'])
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
@ -1383,7 +1383,7 @@ def change_instance_state(filters, desired_state, ec2=None):
|
||||||
await_instances(ids=list(changed) + list(unchanged), state=desired_state)
|
await_instances(ids=list(changed) + list(unchanged), state=desired_state)
|
||||||
|
|
||||||
change_failed = list(to_change - changed)
|
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
|
return changed, change_failed, instances
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue