mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-22 12:50:22 -07:00
Fixing a few bugs in the HostVars performance areas
* Also refresh inventory in the HostVars manager process when things are changed via add_host/group_by * Raise j2undefined rather than return it
This commit is contained in:
parent
4d024fc82a
commit
9f31c073fe
4 changed files with 13 additions and 6 deletions
|
@ -119,7 +119,7 @@ class VariableManager:
|
|||
self._host_vars_files = data.get('host_vars_files', defaultdict(dict))
|
||||
self._group_vars_files = data.get('group_vars_files', defaultdict(dict))
|
||||
self._omit_token = data.get('omit_token', '__omit_place_holder__%s' % sha1(os.urandom(64)).hexdigest())
|
||||
self._inventory = None
|
||||
self._inventory = data.get('inventory', None)
|
||||
|
||||
def _get_cache_entry(self, play=None, host=None, task=None):
|
||||
play_id = "NONE"
|
||||
|
|
|
@ -57,13 +57,16 @@ class HostVars(collections.Mapping):
|
|||
def set_variable_manager(self, variable_manager):
|
||||
self._variable_manager = variable_manager
|
||||
|
||||
def set_inventory(self, inventory):
|
||||
self._inventory = inventory
|
||||
|
||||
def _find_host(self, host_name):
|
||||
return self._inventory.get_host(host_name)
|
||||
|
||||
def __getitem__(self, host_name):
|
||||
host = self._find_host(host_name)
|
||||
if host is None:
|
||||
return j2undefined
|
||||
raise j2undefined
|
||||
|
||||
data = self._variable_manager.get_vars(loader=self._loader, host=host, play=self._play, include_hostvars=False)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue