mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-24 13:50:22 -07:00
Performance optimization in resolving host patterns
Avoid resolving a pattern that is a plain host. When matching a hostname in the hosts_cache, just use the host object from there. When running a task on say 750 hosts, this yields a huge improvement.
This commit is contained in:
parent
539426f612
commit
ff4119adc0
1 changed files with 11 additions and 8 deletions
|
@ -213,15 +213,18 @@ class Inventory(object):
|
||||||
hosts = []
|
hosts = []
|
||||||
|
|
||||||
for p in patterns:
|
for p in patterns:
|
||||||
that = self.__get_hosts(p)
|
# avoid resolving a pattern that is a plain host
|
||||||
if p.startswith("!"):
|
if p in self._hosts_cache:
|
||||||
hosts = [ h for h in hosts if h not in that ]
|
hosts.append(self.get_host(p))
|
||||||
elif p.startswith("&"):
|
|
||||||
hosts = [ h for h in hosts if h in that ]
|
|
||||||
else:
|
else:
|
||||||
to_append = [ h for h in that if h.name not in [ y.name for y in hosts ] ]
|
that = self.__get_hosts(p)
|
||||||
hosts.extend(to_append)
|
if p.startswith("!"):
|
||||||
|
hosts = [ h for h in hosts if h not in that ]
|
||||||
|
elif p.startswith("&"):
|
||||||
|
hosts = [ h for h in hosts if h in that ]
|
||||||
|
else:
|
||||||
|
to_append = [ h for h in that if h.name not in [ y.name for y in hosts ] ]
|
||||||
|
hosts.extend(to_append)
|
||||||
return hosts
|
return hosts
|
||||||
|
|
||||||
def __get_hosts(self, pattern):
|
def __get_hosts(self, pattern):
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue