From 3c3e9c3b36cba0aafe8d64e33b9aea41c85b2211 Mon Sep 17 00:00:00 2001 From: mechaxl Date: Wed, 31 May 2017 13:06:31 -0500 Subject: [PATCH] Fixing policy sorting for Python 3 --- lib/ansible/module_utils/ec2.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/ansible/module_utils/ec2.py b/lib/ansible/module_utils/ec2.py index d556d33a65..38c8814b5e 100644 --- a/lib/ansible/module_utils/ec2.py +++ b/lib/ansible/module_utils/ec2.py @@ -570,7 +570,9 @@ def sort_json_policy_dict(policy_dict): else: checked_list.append(item) - checked_list.sort() + # Sort list. If it's a list of dictionaries, sort by tuple of key-value + # pairs, since Python 3 doesn't allow comparisons such as `<` between dictionaries. + checked_list.sort(key=lambda x: sorted(x.items()) if isinstance(x, dict) else x) return checked_list ordered_policy_dict = {}