diff --git a/lib/ansible/template/__init__.py b/lib/ansible/template/__init__.py index 095e18740a..709ee03ef8 100644 --- a/lib/ansible/template/__init__.py +++ b/lib/ansible/template/__init__.py @@ -299,6 +299,7 @@ class Templar: # Check to see if the string we are trying to render is just referencing a single # var. In this case we don't want to accidentally change the type of the variable # to a string by using the jinja template renderer. We just want to pass it. + var_name = None only_one = self.SINGLE_VAR.match(variable) if only_one: var_name = only_one.group(1) @@ -313,7 +314,7 @@ class Templar: variable_hash = sha1(text_type(variable).encode('utf-8')) options_hash = sha1((text_type(preserve_trailing_newlines) + text_type(escape_backslashes) + text_type(fail_on_undefined) + text_type(overrides)).encode('utf-8')) sha1_hash = variable_hash.hexdigest() + options_hash.hexdigest() - if sha1_hash in self._cached_result: + if var_name not in (None, 'item') and sha1_hash in self._cached_result: result = self._cached_result[sha1_hash] else: result = self._do_template(variable, preserve_trailing_newlines=preserve_trailing_newlines, escape_backslashes=escape_backslashes, fail_on_undefined=fail_on_undefined, overrides=overrides) @@ -327,10 +328,13 @@ class Templar: else: # FIXME: if the safe_eval raised an error, should we do something with it? pass - self._cached_result[sha1_hash] = result + # we only cache in the case where we have a single variable + # name, to make sure we're not putting things which may otherwise + # be dynamic in the cache (filters, lookups, etc.) + if var_name not in (None, 'item'): + self._cached_result[sha1_hash] = result - #return self._clean_data(result) return result elif isinstance(variable, (list, tuple)): diff --git a/lib/ansible/vars/__init__.py b/lib/ansible/vars/__init__.py index fd912ceaec..a332bbd2c7 100644 --- a/lib/ansible/vars/__init__.py +++ b/lib/ansible/vars/__init__.py @@ -272,7 +272,6 @@ class VariableManager: # we assume each item in the list is itself a list, as we # support "conditional includes" for vars_files, which mimics # the with_first_found mechanism. - #vars_file_list = templar.template(vars_file_item) vars_file_list = vars_file_item if not isinstance(vars_file_list, list): vars_file_list = [ vars_file_list ]