mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
ec2: check for changes
In the ec2 module, if an id is specified, check if there have been any changes. If not, return changed=False Fixes #3746
This commit is contained in:
parent
d485abe2e7
commit
0c1f6b4f51
1 changed files with 7 additions and 5 deletions
|
@ -396,7 +396,10 @@ def create_instances(module, ec2):
|
||||||
|
|
||||||
# Both min_count and max_count equal count parameter. This means the launch request is explicit (we want count, or fail) in how many instances we want.
|
# Both min_count and max_count equal count parameter. This means the launch request is explicit (we want count, or fail) in how many instances we want.
|
||||||
|
|
||||||
if count_remaining > 0:
|
if count_remaining == 0:
|
||||||
|
changed = False
|
||||||
|
else:
|
||||||
|
changed = True
|
||||||
try:
|
try:
|
||||||
params = {'image_id': image,
|
params = {'image_id': image,
|
||||||
'key_name': key_name,
|
'key_name': key_name,
|
||||||
|
@ -465,7 +468,7 @@ def create_instances(module, ec2):
|
||||||
created_instance_ids.append(inst.id)
|
created_instance_ids.append(inst.id)
|
||||||
instance_dict_array.append(d)
|
instance_dict_array.append(d)
|
||||||
|
|
||||||
return (instance_dict_array, created_instance_ids)
|
return (instance_dict_array, created_instance_ids, changed)
|
||||||
|
|
||||||
|
|
||||||
def terminate_instances(module, ec2, instance_ids):
|
def terminate_instances(module, ec2, instance_ids):
|
||||||
|
@ -578,14 +581,13 @@ def main():
|
||||||
|
|
||||||
elif module.params.get('state') == 'present':
|
elif module.params.get('state') == 'present':
|
||||||
# Changed is always set to true when provisioning new instances
|
# Changed is always set to true when provisioning new instances
|
||||||
changed = True
|
|
||||||
if not module.params.get('key_name'):
|
if not module.params.get('key_name'):
|
||||||
module.fail_json(msg='key_name parameter is required for new instance')
|
module.fail_json(msg='key_name parameter is required for new instance')
|
||||||
if not module.params.get('image'):
|
if not module.params.get('image'):
|
||||||
module.fail_json(msg='image parameter is required for new instance')
|
module.fail_json(msg='image parameter is required for new instance')
|
||||||
(instance_dict_array, new_instance_ids) = create_instances(module, ec2)
|
(instance_dict_array, new_instance_ids, changed) = create_instances(module, ec2)
|
||||||
|
|
||||||
module.exit_json(changed=True, instance_ids=new_instance_ids, instances=instance_dict_array)
|
module.exit_json(changed=changed, instance_ids=new_instance_ids, instances=instance_dict_array)
|
||||||
|
|
||||||
|
|
||||||
# this is magic, see lib/ansible/module_common.py
|
# this is magic, see lib/ansible/module_common.py
|
||||||
|
|
Loading…
Reference in a new issue