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

@@ -36,6 +36,7 @@ from ansible.module_utils.six import string_types
from ansible.module_utils._text import to_bytes, to_text
from ansible.parsing.utils.addresses import parse_address
from ansible.plugins.loader import inventory_loader
from ansible.utils.helpers import deduplicate_list
from ansible.utils.path import unfrackpath
from ansible.utils.display import Display
@@ -369,8 +370,7 @@ class InventoryManager(object):
# exclude hosts mentioned in any restriction (ex: failed hosts)
hosts = [h for h in hosts if h.name in self._restriction]
seen = set()
self._hosts_patterns_cache[pattern_hash] = [x for x in hosts if x not in seen and not seen.add(x)]
self._hosts_patterns_cache[pattern_hash] = deduplicate_list(hosts)
# sort hosts list if needed (should only happen when called from strategy)
if order in ['sorted', 'reverse_sorted']: