diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-08-07 13:26:57 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-08-07 13:26:57 +0000 |
commit | d4dfa10cd25391c61bd21fa7c3e08d1ba955b52a (patch) | |
tree | 3492abc44856eb055528b4163280c0e4a4d0e7cc /lib/ansible/vars | |
parent | Releasing progress-linux version 2.17.1-1~progress7.99u1. (diff) | |
download | ansible-core-d4dfa10cd25391c61bd21fa7c3e08d1ba955b52a.tar.xz ansible-core-d4dfa10cd25391c61bd21fa7c3e08d1ba955b52a.zip |
Merging upstream version 2.17.2.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'lib/ansible/vars')
-rw-r--r-- | lib/ansible/vars/hostvars.py | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/lib/ansible/vars/hostvars.py b/lib/ansible/vars/hostvars.py index bb0372e..6f8491d 100644 --- a/lib/ansible/vars/hostvars.py +++ b/lib/ansible/vars/hostvars.py @@ -18,6 +18,7 @@ from __future__ import annotations from collections.abc import Mapping +from functools import cached_property from ansible import constants as C from ansible.template import Templar, AnsibleUndefined @@ -114,9 +115,12 @@ class HostVarsVars(Mapping): def __init__(self, variables, loader): self._vars = variables self._loader = loader + + @cached_property + def _templar(self): # NOTE: this only has access to the host's own vars, # so templates that depend on vars in other scopes will not work. - self._templar = Templar(variables=self._vars, loader=self._loader) + return Templar(variables=self._vars, loader=self._loader) def __getitem__(self, var): return self._templar.template(self._vars[var], fail_on_undefined=False, static_vars=C.INTERNAL_STATIC_VARS) @@ -132,3 +136,10 @@ class HostVarsVars(Mapping): def __repr__(self): return repr(self._templar.template(self._vars, fail_on_undefined=False, static_vars=C.INTERNAL_STATIC_VARS)) + + def __getstate__(self): + ''' override serialization here to avoid + pickle issues with templar and Jinja native''' + state = self.__dict__.copy() + state.pop('_templar', None) + return state |