1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

Restoring templating of hostvars returned by __getitem__

This commit is contained in:
James Cammarata 2015-11-17 10:19:56 -05:00
parent 9f31c073fe
commit f10d2c57c8

View file

@ -70,23 +70,14 @@ class HostVars(collections.Mapping):
data = self._variable_manager.get_vars(loader=self._loader, host=host, play=self._play, include_hostvars=False)
#****************************************************
# TESTING REMOVAL OF THIS
#****************************************************
# Since we template much later now in 2.0, it may be completely unrequired to do
# a full template of the vars returned above, which is quite costly in time when
# the result is large.
# Using cache in order to avoid template call
#sha1_hash = sha1(str(data).encode('utf-8')).hexdigest()
#if sha1_hash in self._cached_result:
# result = self._cached_result[sha1_hash]
#else:
# templar = Templar(variables=data, loader=self._loader)
# result = templar.template(data, fail_on_undefined=False, static_vars=STATIC_VARS)
# self._cached_result[sha1_hash] = result
#return result
#****************************************************
return data
sha1_hash = sha1(str(data).encode('utf-8')).hexdigest()
if sha1_hash in self._cached_result:
result = self._cached_result[sha1_hash]
else:
templar = Templar(variables=data, loader=self._loader)
result = templar.template(data, fail_on_undefined=False, static_vars=STATIC_VARS)
self._cached_result[sha1_hash] = result
return result
def __contains__(self, host_name):
return self._find_host(host_name) is not None