From 68f177d381dea109b3eddfc7a8d30130c17b8722 Mon Sep 17 00:00:00 2001 From: Brian Coca Date: Mon, 16 Oct 2017 16:43:56 -0400 Subject: [PATCH] py2/py3 safer shas on hostvars (#31788) * py2/py3 safer shas on hostvars * plain bytes --- lib/ansible/vars/hostvars.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/ansible/vars/hostvars.py b/lib/ansible/vars/hostvars.py index 27d086a957..d1f1668cca 100644 --- a/lib/ansible/vars/hostvars.py +++ b/lib/ansible/vars/hostvars.py @@ -23,6 +23,7 @@ import collections from jinja2.runtime import Undefined +from ansible.module_utils._text import to_bytes from ansible.template import Templar STATIC_VARS = [ @@ -85,7 +86,7 @@ class HostVars(collections.Mapping): def __getitem__(self, host_name): data = self.raw_get(host_name) - sha1_hash = sha1(str(data).encode('utf-8')).hexdigest() + sha1_hash = sha1(to_bytes(data)).hexdigest() if sha1_hash not in self._cached_result: templar = Templar(variables=data, loader=self._loader) self._cached_result[sha1_hash] = templar.template(data, fail_on_undefined=False, static_vars=STATIC_VARS)