Commit f433e709 by James Cammarata

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
parent 8ef28253
......@@ -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]
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment