Don't use play vars in HostVars

Fixes #13398
pull/13391/head
James Cammarata 9 years ago
parent 8ff67e0494
commit a183972477

@ -188,7 +188,6 @@ class TaskQueueManager:
pass pass
hostvars = HostVars( hostvars = HostVars(
play=new_play,
inventory=self._inventory, inventory=self._inventory,
variable_manager=self._variable_manager, variable_manager=self._variable_manager,
loader=self._loader, loader=self._loader,

@ -43,7 +43,6 @@ from ansible.template import Templar
from ansible.utils.debug import debug from ansible.utils.debug import debug
from ansible.utils.listify import listify_lookup_plugin_terms from ansible.utils.listify import listify_lookup_plugin_terms
from ansible.utils.vars import combine_vars from ansible.utils.vars import combine_vars
from ansible.vars.hostvars import HostVars
from ansible.vars.unsafe_proxy import wrap_var from ansible.vars.unsafe_proxy import wrap_var
try: try:
@ -171,7 +170,8 @@ class VariableManager:
return data return data
# FIXME: include_hostvars is no longer used, and should be removed, but
# all other areas of code calling get_vars need to be fixed too
def get_vars(self, loader, play=None, host=None, task=None, include_hostvars=True, include_delegate_to=True, use_cache=True): def get_vars(self, loader, play=None, host=None, task=None, include_hostvars=True, include_delegate_to=True, use_cache=True):
''' '''
Returns the variables, with optional "context" given via the parameters Returns the variables, with optional "context" given via the parameters
@ -367,17 +367,6 @@ class VariableManager:
variables['groups'] = dict() variables['groups'] = dict()
for (group_name, group) in iteritems(self._inventory.groups): for (group_name, group) in iteritems(self._inventory.groups):
variables['groups'][group_name] = [h.name for h in group.get_hosts()] variables['groups'][group_name] = [h.name for h in group.get_hosts()]
#if include_hostvars:
# hostvars_cache_entry = self._get_cache_entry(play=play)
# if hostvars_cache_entry in HOSTVARS_CACHE:
# hostvars = HOSTVARS_CACHE[hostvars_cache_entry]
# else:
# hostvars = HostVars(play=play, inventory=self._inventory, loader=loader, variable_manager=self)
# HOSTVARS_CACHE[hostvars_cache_entry] = hostvars
# variables['hostvars'] = hostvars
# variables['vars'] = hostvars[host.get_name()]
if play: if play:
variables['role_names'] = [r._role_name for r in play.roles] variables['role_names'] = [r._role_name for r in play.roles]

@ -46,11 +46,10 @@ __all__ = ['HostVars']
class HostVars(collections.Mapping): class HostVars(collections.Mapping):
''' A special view of vars_cache that adds values from the inventory when needed. ''' ''' A special view of vars_cache that adds values from the inventory when needed. '''
def __init__(self, play, inventory, variable_manager, loader): def __init__(self, inventory, variable_manager, loader):
self._lookup = dict() self._lookup = dict()
self._inventory = inventory self._inventory = inventory
self._loader = loader self._loader = loader
self._play = play
self._variable_manager = variable_manager self._variable_manager = variable_manager
self._cached_result = dict() self._cached_result = dict()
@ -68,7 +67,7 @@ class HostVars(collections.Mapping):
if host is None: if host is None:
raise j2undefined raise j2undefined
data = self._variable_manager.get_vars(loader=self._loader, host=host, play=self._play, include_hostvars=False) data = self._variable_manager.get_vars(loader=self._loader, host=host, include_hostvars=False)
sha1_hash = sha1(str(data).encode('utf-8')).hexdigest() sha1_hash = sha1(str(data).encode('utf-8')).hexdigest()
if sha1_hash in self._cached_result: if sha1_hash in self._cached_result:

Loading…
Cancel
Save