From bb9433f19841b4315efc32a0b2b9952bfc73c6cb Mon Sep 17 00:00:00 2001 From: James Cammarata Date: Mon, 3 Nov 2014 09:43:26 -0600 Subject: [PATCH] Fail in ec2 if exact_count is specified without using count_tag Fixes ansible/ansible#9431 --- lib/ansible/modules/cloud/ec2.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/ansible/modules/cloud/ec2.py b/lib/ansible/modules/cloud/ec2.py index a82b6a6b637..dccd0668939 100644 --- a/lib/ansible/modules/cloud/ec2.py +++ b/lib/ansible/modules/cloud/ec2.py @@ -660,6 +660,11 @@ def enforce_count(module, ec2): count_tag = module.params.get('count_tag') zone = module.params.get('zone') + # fail here if the exact count was specified without filtering + # on a tag, as this may lead to a undesired removal of instances + if exact_count and count_tag is None: + module.fail_json(msg="you must use the 'count_tag' option with exact_count") + reservations, instances = find_running_instances_by_count_tag(module, ec2, count_tag, zone) changed = None