mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-06-28 03:00:23 -07:00
Fixing up host pattern caching to avoid bugs
* Always cache and return unique list objects, so that if the list is changed later it does not impact the cached results * Take additional parameters and the type of the pattern into account when building the hash string
This commit is contained in:
parent
e8f83dcba3
commit
c753ae6e22
1 changed files with 8 additions and 3 deletions
|
@ -166,9 +166,14 @@ class Inventory(object):
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# Check if pattern already computed
|
# Check if pattern already computed
|
||||||
pattern_hash = str(pattern)
|
if isinstance(pattern, list):
|
||||||
|
pattern_hash = u":".join(pattern)
|
||||||
|
else:
|
||||||
|
pattern_hash = pattern
|
||||||
|
pattern_hash += u":%s" % ignore_limits_and_restrictions
|
||||||
|
|
||||||
if pattern_hash in HOSTS_PATTERNS_CACHE:
|
if pattern_hash in HOSTS_PATTERNS_CACHE:
|
||||||
return HOSTS_PATTERNS_CACHE[pattern_hash]
|
return HOSTS_PATTERNS_CACHE[pattern_hash][:]
|
||||||
|
|
||||||
patterns = Inventory.split_host_pattern(pattern)
|
patterns = Inventory.split_host_pattern(pattern)
|
||||||
hosts = self._evaluate_patterns(patterns)
|
hosts = self._evaluate_patterns(patterns)
|
||||||
|
@ -184,7 +189,7 @@ class Inventory(object):
|
||||||
if self._restriction is not None:
|
if self._restriction is not None:
|
||||||
hosts = [ h for h in hosts if h in self._restriction ]
|
hosts = [ h for h in hosts if h in self._restriction ]
|
||||||
|
|
||||||
HOSTS_PATTERNS_CACHE[pattern_hash] = hosts
|
HOSTS_PATTERNS_CACHE[pattern_hash] = hosts[:]
|
||||||
return hosts
|
return hosts
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue