diff options
author | Marc Pujol <kilburn@la3.org> | 2014-05-30 08:54:48 +0200 |
---|---|---|
committer | James Cammarata <jimi@sngx.net> | 2014-06-09 14:10:57 -0500 |
commit | d8c8c0823ad816e4fc02f49ce024f25e3b7abcc2 (patch) | |
tree | 9bf1460c1bfa098f3bcfd6ab8dcaab26d9110440 | |
parent | 3801be693baa32f7e98ae454aea02326981e9f6f (diff) | |
download | ansible-d8c8c0823ad816e4fc02f49ce024f25e3b7abcc2.tar.gz |
Merge and intersect lists without using sets.
Using sets for these operations is dangerous because sets cannot contain
certain object types (such as lists) and their iteration order is
undefined.
Fixes #7596
-rw-r--r-- | lib/ansible/utils/__init__.py | 22 |
1 files changed, 10 insertions, 12 deletions
diff --git a/lib/ansible/utils/__init__.py b/lib/ansible/utils/__init__.py index b1916371fc..59324eb84e 100644 --- a/lib/ansible/utils/__init__.py +++ b/lib/ansible/utils/__init__.py @@ -1005,21 +1005,19 @@ def is_list_of_strings(items): return False return True -def _listify(a): - if not isinstance(a, (list, tuple)): - return [a,] - else: - return a - def list_union(a, b): - set_a = set(_listify(a)) - set_b = set(_listify(b)) - return list(set_a.union(set_b)) + result = list(a) + for i in b: + if i not in result: + result.append(i) + return result def list_intersection(a, b): - set_a = set(_listify(a)) - set_b = set(_listify(b)) - return list(set_a.intersection(set_b)) + result = [] + for i in a: + if i in b: + result.append(i) + return result def safe_eval(expr, locals={}, include_exceptions=False): ''' |