From 79b9c585eac59597e75f25d8ec675d010075e8f5 Mon Sep 17 00:00:00 2001 From: Brian Coca Date: Thu, 20 Apr 2017 18:02:56 -0400 Subject: [PATCH] less code (cherry picked from commit 20d9f79a5250e764ffeddb046aeb82b7824ed952) --- lib/ansible/vars/hostvars.py | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/lib/ansible/vars/hostvars.py b/lib/ansible/vars/hostvars.py index 0b34248a54a..bcf2f00c18c 100644 --- a/lib/ansible/vars/hostvars.py +++ b/lib/ansible/vars/hostvars.py @@ -80,13 +80,10 @@ class HostVars(collections.Mapping): def __getitem__(self, host_name): data = self.raw_get(host_name) sha1_hash = sha1(str(data).encode('utf-8')).hexdigest() - if sha1_hash in self._cached_result: - result = self._cached_result[sha1_hash] - else: + if sha1_hash not in self._cached_result: 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 + self._cached_result[sha1_hash] = templar.template(data, fail_on_undefined=False, static_vars=STATIC_VARS) + return self._cached_result[sha1_hash] def set_host_variable(self, host, varname, value): self._variable_manager.set_host_variable(host, varname, value)