diff --git a/lib/ansible/vars/__init__.py b/lib/ansible/vars/__init__.py index 8c098b30f1..4e8d6bda3c 100644 --- a/lib/ansible/vars/__init__.py +++ b/lib/ansible/vars/__init__.py @@ -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() diff --git a/lib/ansible/vars/hostvars.py b/lib/ansible/vars/hostvars.py index 45b3340229..166bdbe257 100644 --- a/lib/ansible/vars/hostvars.py +++ b/lib/ansible/vars/hostvars.py @@ -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]