From 44171b70c2b34b929f28497810ffbe6b88151e51 Mon Sep 17 00:00:00 2001 From: Sloane Hertel Date: Fri, 26 Jan 2018 11:51:17 -0500 Subject: [PATCH] [ec2] return instances sorted by id (#35359) --- lib/ansible/modules/cloud/amazon/ec2.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/lib/ansible/modules/cloud/amazon/ec2.py b/lib/ansible/modules/cloud/amazon/ec2.py index f7504dec54..cb440ebb76 100644 --- a/lib/ansible/modules/cloud/amazon/ec2.py +++ b/lib/ansible/modules/cloud/amazon/ec2.py @@ -1755,6 +1755,14 @@ def main(): else: (tagged_instances, instance_dict_array, new_instance_ids, changed) = enforce_count(module, ec2, vpc) + # Always return instances in the same order + if new_instance_ids: + new_instance_ids.sort() + if instance_dict_array: + instance_dict_array.sort(key=lambda x: x['id']) + if tagged_instances: + tagged_instances.sort(key=lambda x: x['id']) + module.exit_json(changed=changed, instance_ids=new_instance_ids, instances=instance_dict_array, tagged_instances=tagged_instances)