diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-25 02:51:10 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-25 02:51:10 +0000 |
commit | eee9982be19a16d860b7e9dde05850e7f8c2276a (patch) | |
tree | 21d77352ca156d2d5671ffcdc88a65d4f7fb97b0 /lib/ansible/vars/hostvars.py | |
parent | Releasing progress-linux version 2.16.5-1~progress7.99u1. (diff) | |
download | ansible-core-eee9982be19a16d860b7e9dde05850e7f8c2276a.tar.xz ansible-core-eee9982be19a16d860b7e9dde05850e7f8c2276a.zip |
Merging upstream version 2.16.6.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'lib/ansible/vars/hostvars.py')
-rw-r--r-- | lib/ansible/vars/hostvars.py | 28 |
1 files changed, 6 insertions, 22 deletions
diff --git a/lib/ansible/vars/hostvars.py b/lib/ansible/vars/hostvars.py index 6222954..a76811b 100644 --- a/lib/ansible/vars/hostvars.py +++ b/lib/ansible/vars/hostvars.py @@ -21,26 +21,9 @@ __metaclass__ = type from collections.abc import Mapping +from ansible import constants as C from ansible.template import Templar, AnsibleUndefined -STATIC_VARS = [ - 'ansible_version', - 'ansible_play_hosts', - 'ansible_dependent_role_names', - 'ansible_play_role_names', - 'ansible_role_names', - 'inventory_hostname', - 'inventory_hostname_short', - 'inventory_file', - 'inventory_dir', - 'groups', - 'group_names', - 'omit', - 'playbook_dir', - 'play_hosts', - 'role_names', - 'ungrouped', -] __all__ = ['HostVars', 'HostVarsVars'] @@ -134,10 +117,12 @@ class HostVarsVars(Mapping): def __init__(self, variables, loader): self._vars = variables self._loader = loader + # 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) def __getitem__(self, var): - templar = Templar(variables=self._vars, loader=self._loader) - return templar.template(self._vars[var], fail_on_undefined=False, static_vars=STATIC_VARS) + return self._templar.template(self._vars[var], fail_on_undefined=False, static_vars=C.INTERNAL_STATIC_VARS) def __contains__(self, var): return (var in self._vars) @@ -150,5 +135,4 @@ class HostVarsVars(Mapping): return len(self._vars.keys()) def __repr__(self): - templar = Templar(variables=self._vars, loader=self._loader) - return repr(templar.template(self._vars, fail_on_undefined=False, static_vars=STATIC_VARS)) + return repr(self._templar.template(self._vars, fail_on_undefined=False, static_vars=C.INTERNAL_STATIC_VARS)) |