mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Allow hostvars cache to be invalidated so hostvars contain all hosts after add_host
Fixes #12925
This commit is contained in:
parent
2825c188bd
commit
cace91df56
2 changed files with 11 additions and 2 deletions
|
@ -226,7 +226,7 @@ class StrategyBase:
|
|||
result_item = result[1]
|
||||
new_host_info = result_item.get('add_host', dict())
|
||||
|
||||
self._add_host(new_host_info)
|
||||
self._add_host(new_host_info, iterator)
|
||||
|
||||
elif result[0] == 'add_group':
|
||||
host = result[1]
|
||||
|
@ -309,7 +309,7 @@ class StrategyBase:
|
|||
|
||||
return ret_results
|
||||
|
||||
def _add_host(self, host_info):
|
||||
def _add_host(self, host_info, iterator):
|
||||
'''
|
||||
Helper function to add a new host to inventory based on a task result.
|
||||
'''
|
||||
|
@ -352,6 +352,10 @@ class StrategyBase:
|
|||
# patterns may have referenced the group
|
||||
self._inventory.clear_pattern_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)
|
||||
|
||||
def _add_group(self, host, result_item):
|
||||
'''
|
||||
Helper function to add a group (if it does not exist), and to assign the
|
||||
|
|
|
@ -332,6 +332,11 @@ class VariableManager:
|
|||
debug("done with get_vars()")
|
||||
return all_vars
|
||||
|
||||
def invalidate_hostvars_cache(self, play):
|
||||
hostvars_cache_entry = self._get_cache_entry(play=play)
|
||||
if hostvars_cache_entry in HOSTVARS_CACHE:
|
||||
del HOSTVARS_CACHE[hostvars_cache_entry]
|
||||
|
||||
def _get_magic_variables(self, loader, play, host, task, include_hostvars, include_delegate_to):
|
||||
'''
|
||||
Returns a dictionary of so-called "magic" variables in Ansible,
|
||||
|
|
Loading…
Reference in a new issue