mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
[cloud] Only enforce state (running/stopped/etc) in EC2 "exact_count" when state is specified (#31648)
fix issue in ec2 module where exact count would create new instances if the instane state is stopped or terminated
This commit is contained in:
parent
90b6178e61
commit
53e476ad4e
1 changed files with 7 additions and 2 deletions
|
@ -639,13 +639,18 @@ except ImportError:
|
||||||
|
|
||||||
def find_running_instances_by_count_tag(module, ec2, vpc, count_tag, zone=None):
|
def find_running_instances_by_count_tag(module, ec2, vpc, count_tag, zone=None):
|
||||||
|
|
||||||
# get reservations for instances that match tag(s) and are running
|
# get reservations for instances that match tag(s) and are in the desired state
|
||||||
reservations = get_reservations(module, ec2, vpc, tags=count_tag, state="running", zone=zone)
|
state = module.params.get('state')
|
||||||
|
if state not in ['running', 'stopped']:
|
||||||
|
state = None
|
||||||
|
reservations = get_reservations(module, ec2, vpc, tags=count_tag, state=state, zone=zone)
|
||||||
|
|
||||||
instances = []
|
instances = []
|
||||||
for res in reservations:
|
for res in reservations:
|
||||||
if hasattr(res, 'instances'):
|
if hasattr(res, 'instances'):
|
||||||
for inst in res.instances:
|
for inst in res.instances:
|
||||||
|
if inst.state == 'terminated':
|
||||||
|
continue
|
||||||
instances.append(inst)
|
instances.append(inst)
|
||||||
|
|
||||||
return reservations, instances
|
return reservations, instances
|
||||||
|
|
Loading…
Reference in a new issue