mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Cache against hosts pattern (fix a part of problem describe in https://github.com/ansible/ansible/issues/13023).
This commit is contained in:
parent
30f827d92d
commit
e0aa3ff232
1 changed files with 8 additions and 0 deletions
|
@ -37,6 +37,8 @@ from ansible.plugins import vars_loader
|
|||
from ansible.utils.vars import combine_vars
|
||||
from ansible.parsing.utils.addresses import parse_address
|
||||
|
||||
HOSTS_PATTERNS_CACHE = {}
|
||||
|
||||
try:
|
||||
from __main__ import display
|
||||
except ImportError:
|
||||
|
@ -156,6 +158,11 @@ class Inventory(object):
|
|||
or applied subsets
|
||||
"""
|
||||
|
||||
# Check if pattern already computed
|
||||
pattern_hash = str(pattern)
|
||||
if pattern_hash in HOSTS_PATTERNS_CACHE:
|
||||
return HOSTS_PATTERNS_CACHE[pattern_hash]
|
||||
|
||||
patterns = Inventory.split_host_pattern(pattern)
|
||||
hosts = self._evaluate_patterns(patterns)
|
||||
|
||||
|
@ -170,6 +177,7 @@ class Inventory(object):
|
|||
if self._restriction is not None:
|
||||
hosts = [ h for h in hosts if h in self._restriction ]
|
||||
|
||||
HOSTS_PATTERNS_CACHE[pattern_hash] = hosts
|
||||
return hosts
|
||||
|
||||
@classmethod
|
||||
|
|
Loading…
Reference in a new issue