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
reviewable/pr18780/r1
Lorin Hochstein 11 years ago
parent fea38f44ac
commit 3840a9f8f5

@ -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.
if count_remaining > 0:
if count_remaining == 0:
changed = False
else:
changed = True
try:
params = {'image_id': image,
'key_name': key_name,
@ -465,7 +468,7 @@ def create_instances(module, ec2):
created_instance_ids.append(inst.id)
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):
@ -578,14 +581,13 @@ def main():
elif module.params.get('state') == 'present':
# Changed is always set to true when provisioning new instances
changed = True
if not module.params.get('key_name'):
module.fail_json(msg='key_name parameter is required for new instance')
if not module.params.get('image'):
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

Loading…
Cancel
Save