mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-22 12:50:22 -07:00
Use static vars when computing host vars known to be static (inventory_hostname, inventory_dir etc.).
This commit is contained in:
parent
e0aa3ff232
commit
ccbdd6229a
2 changed files with 13 additions and 3 deletions
|
@ -28,6 +28,13 @@ from ansible import constants as C
|
|||
from ansible.inventory.host import Host
|
||||
from ansible.template import Templar
|
||||
|
||||
STATIC_VARS = [
|
||||
'inventory_hostname', 'inventory_hostname_short',
|
||||
'inventory_file', 'inventory_dir', 'playbook_dir',
|
||||
'ansible_play_hosts', 'play_hosts', 'groups', 'ungrouped', 'group_names',
|
||||
'ansible_version', 'omit', 'role_names'
|
||||
]
|
||||
|
||||
try:
|
||||
from hashlib import sha1
|
||||
except ImportError:
|
||||
|
@ -81,7 +88,7 @@ class HostVars(collections.Mapping):
|
|||
result = self._cached_result[sha1_hash]
|
||||
else:
|
||||
templar = Templar(variables=data, loader=self._loader)
|
||||
result = templar.template(data, fail_on_undefined=False)
|
||||
result = templar.template(data, fail_on_undefined=False, static_vars=STATIC_VARS)
|
||||
self._cached_result[sha1_hash] = result
|
||||
return result
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue