From 25a9ababcc17987fd1ea17f734b490c4c40d788d Mon Sep 17 00:00:00 2001 From: Sloane Hertel Date: Thu, 17 Aug 2017 15:17:13 -0400 Subject: [PATCH] ec2.py: filter by client-token if id is specified (#26114) fixes #26021 --- lib/ansible/modules/cloud/amazon/ec2.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lib/ansible/modules/cloud/amazon/ec2.py b/lib/ansible/modules/cloud/amazon/ec2.py index a1263ef630..b64abd3a46 100644 --- a/lib/ansible/modules/cloud/amazon/ec2.py +++ b/lib/ansible/modules/cloud/amazon/ec2.py @@ -707,6 +707,9 @@ def get_reservations(module, ec2, vpc, tags=None, state=None, zone=None): if zone: filters.update({'availability-zone': zone}) + if module.params.get('id'): + filters['client-token'] = module.params['id'] + results = ec2.get_all_instances(filters=filters) return results @@ -1423,6 +1426,8 @@ def startstop_instances(module, ec2, instance_ids, state, instance_tags): for key, value in instance_tags.items(): filters["tag:" + key] = value + if module.params.get('id'): + filters['client-token'] = module.params['id'] # Check that our instances are not in the state we want to take # Check (and eventually change) instances attributes and instances state @@ -1548,6 +1553,8 @@ def restart_instances(module, ec2, instance_ids, state, instance_tags): if instance_tags: for key, value in instance_tags.items(): filters["tag:" + key] = value + if module.params.get('id'): + filters['client-token'] = module.params['id'] # Check that our instances are not in the state we want to take