summaryrefslogtreecommitdiff
path: root/lib/ansible/vars
diff options
context:
space:
mode:
authorJames Cammarata <jimi@sngx.net>2016-09-21 10:34:57 -0500
committerJames Cammarata <jimi@sngx.net>2016-09-21 13:16:08 -0500
commit23651b657e53f9b65c8a157bd370027d5f9b7abb (patch)
treef3d58e038a0fbffe45082a37eab82d9e96cd3fa3 /lib/ansible/vars
parent04165fb6c042f92b168a5818e7d7d5be220b84cd (diff)
downloadansible-23651b657e53f9b65c8a157bd370027d5f9b7abb.tar.gz
Create a raw lookup for hostvars that does not template the data
When using hostvars to get extra connection-specific vars for connection plugins, use this raw lookup to avoid prematurely templating all of the hostvar data (triggering unnecessary lookups). Fixes #17024
Diffstat (limited to 'lib/ansible/vars')
-rw-r--r--lib/ansible/vars/hostvars.py10
1 files changed, 8 insertions, 2 deletions
diff --git a/lib/ansible/vars/hostvars.py b/lib/ansible/vars/hostvars.py
index 1e2ac7e292..31d30ad801 100644
--- a/lib/ansible/vars/hostvars.py
+++ b/lib/ansible/vars/hostvars.py
@@ -68,13 +68,19 @@ class HostVars(collections.Mapping):
host = self._inventory.get_host(host_name)
return host
- def __getitem__(self, host_name):
+ def raw_get(self, host_name):
+ '''
+ Similar to __getitem__, however the returned data is not run through
+ the templating engine to expand variables in the hostvars.
+ '''
host = self._find_host(host_name)
if host is None:
raise j2undefined
- data = self._variable_manager.get_vars(loader=self._loader, host=host, include_hostvars=False)
+ return self._variable_manager.get_vars(loader=self._loader, host=host, include_hostvars=False)
+ 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]