From 3840a9f8f57016d05c3eed4c4f8eae72488ec649 Mon Sep 17 00:00:00 2001 From: Lorin Hochstein Date: Fri, 2 Aug 2013 22:23:41 -0400 Subject: [PATCH] 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 --- cloud/ec2 | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/cloud/ec2 b/cloud/ec2 index fd712d07126..e6fe50d9eb8 100644 --- a/cloud/ec2 +++ b/cloud/ec2 @@ -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