preserve same order as inventory manager when using host lookup (#55331)

* preserve same order as inventory manager when using inventory_hostnames lookup

add a test

* move generic code
This commit is contained in:
Sloane Hertel 2019-04-18 15:54:03 -04:00 committed by Brian Coca
parent 0330ea616e
commit afb5e02c19
7 changed files with 37 additions and 3 deletions

View file

@ -41,3 +41,11 @@ def object_to_dict(obj, exclude=None):
if exclude is None or not isinstance(exclude, list):
exclude = []
return dict((key, getattr(obj, key)) for key in dir(obj) if not (key.startswith('_') or key in exclude))
def deduplicate_list(original_list):
"""
Creates a deduplicated list with the order in which each item is first found.
"""
seen = set()
return [x for x in original_list if x not in seen and not seen.add(x)]