mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Fix templating of hostvars values
Also adds play information into the hostvars creation, to assure the variable manager used there has access to vars and vars_files Fixes #9501 Fixes #8213 Fixes #7844
This commit is contained in:
parent
8ef28253e3
commit
f433e709f2
2 changed files with 6 additions and 9 deletions
|
@ -219,7 +219,7 @@ class VariableManager:
|
|||
all_vars['groups'] = [group.name for group in host.get_groups()]
|
||||
|
||||
if self._inventory is not None:
|
||||
hostvars = HostVars(vars_manager=self, inventory=self._inventory, loader=loader)
|
||||
hostvars = HostVars(vars_manager=self, play=play, inventory=self._inventory, loader=loader)
|
||||
all_vars['hostvars'] = hostvars
|
||||
all_vars['groups'] = self._inventory.groups_list()
|
||||
|
||||
|
|
|
@ -26,22 +26,19 @@ __all__ = ['HostVars']
|
|||
class HostVars(dict):
|
||||
''' A special view of vars_cache that adds values from the inventory when needed. '''
|
||||
|
||||
def __init__(self, vars_manager, inventory, loader):
|
||||
def __init__(self, vars_manager, play, inventory, loader):
|
||||
self._vars_manager = vars_manager
|
||||
self._play = play
|
||||
self._inventory = inventory
|
||||
self._loader = loader
|
||||
self._lookup = {}
|
||||
|
||||
#self.update(vars_cache)
|
||||
|
||||
def __getitem__(self, host_name):
|
||||
|
||||
if host_name not in self._lookup:
|
||||
host = self._inventory.get_host(host_name)
|
||||
result = self._vars_manager.get_vars(loader=self._loader, host=host)
|
||||
#result.update(self._vars_cache.get(host, {}))
|
||||
#templar = Templar(variables=self._vars_cache, loader=self._loader)
|
||||
#self._lookup[host] = templar.template(result)
|
||||
self._lookup[host_name] = result
|
||||
result = self._vars_manager.get_vars(loader=self._loader, play=self._play, host=host)
|
||||
templar = Templar(variables=result, loader=self._loader)
|
||||
self._lookup[host_name] = templar.template(result)
|
||||
return self._lookup[host_name]
|
||||
|
||||
|
|
Loading…
Reference in a new issue