mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-24 13:50:22 -07:00
[Inventory] Cache the result of enumerating groups and host names
for `VariableManager._get_magic_variables()`. This saves a lot of time re-iterating the nearly always constant global list of groups and their members. Generate once and cache, and invalidate cache in case `add_host:` or `group_by:` are used.
This commit is contained in:
parent
28227546fa
commit
c23b11d212
4 changed files with 38 additions and 11 deletions
|
@ -475,6 +475,9 @@ class StrategyBase:
|
|||
# patterns may have referenced the group
|
||||
self._inventory.clear_pattern_cache()
|
||||
|
||||
# clear cache of group dict, which is used in magic host variables
|
||||
self._inventory.clear_group_dict_cache()
|
||||
|
||||
# also clear the hostvar cache entry for the given play, so that
|
||||
# the new hosts are available if hostvars are referenced
|
||||
self._variable_manager.invalidate_hostvars_cache(play=iterator._play)
|
||||
|
@ -495,6 +498,9 @@ class StrategyBase:
|
|||
group_name = result_item.get('add_group')
|
||||
new_group = self._inventory.get_group(group_name)
|
||||
if not new_group:
|
||||
# clear cache of group dict, which is used in magic host variables
|
||||
self._inventory.clear_group_dict_cache()
|
||||
|
||||
# create the new group and add it to inventory
|
||||
new_group = Group(name=group_name)
|
||||
self._inventory.add_group(new_group)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue