From 3840a9f8f57016d05c3eed4c4f8eae72488ec649 Mon Sep 17 00:00:00 2001 From: Lorin Hochstein Date: Fri, 2 Aug 2013 22:23:41 -0400 Subject: [PATCH 1/2] 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 From 262808cf7cbfd197cde85e6027f452c1f1f07411 Mon Sep 17 00:00:00 2001 From: Lorin Hochstein Date: Fri, 2 Aug 2013 22:31:22 -0400 Subject: [PATCH 2/2] ec2: Removed unused line Remove the reference to the unused "termination_list" parameter in the ec2 module. The instance_ids parameter is the one that contains the list of instance ids to be terminated. --- cloud/ec2 | 1 - 1 file changed, 1 deletion(-) diff --git a/cloud/ec2 b/cloud/ec2 index e6fe50d9eb8..7639d6195a7 100644 --- a/cloud/ec2 +++ b/cloud/ec2 @@ -545,7 +545,6 @@ def main(): ec2_secret_key = module.params.get('ec2_secret_key') ec2_access_key = module.params.get('ec2_access_key') region = module.params.get('region') - termination_list = module.params.get('termination_list') # allow eucarc environment variables to be used if ansible vars aren't set