mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-05-07 13:52:54 +00:00
Add set_fact_persistent action and module. (#26153)
* Add 'cacheable' param to set_fact action and module. Used just like set_fact, except facts set with cacheable: true will be stored in the fact cache if fact caching is enabled. set_fact normally only sets facts in the non_persistent_fact_cache, so they are lost between invocations. * update set_facts docs * use 'ansible_facts_cacheable' in module/actions result * pop fact cacheable related items out of args/results We dont want to use 'ansible_facts_cacheable' result item or 'cacheable' arg as actual facts, so pop them out of the dicts.
This commit is contained in:
@@ -511,12 +511,14 @@ class StrategyBase:
|
||||
for target_host in host_list:
|
||||
self._variable_manager.set_host_variable(target_host, var_name, var_value)
|
||||
else:
|
||||
cacheable = result_item.pop('ansible_facts_cacheable', True)
|
||||
for target_host in host_list:
|
||||
if original_task.action == 'set_fact':
|
||||
self._variable_manager.set_nonpersistent_facts(target_host, result_item['ansible_facts'].copy())
|
||||
else:
|
||||
if cacheable:
|
||||
self._variable_manager.set_host_facts(target_host, result_item['ansible_facts'].copy())
|
||||
|
||||
# If we are setting a fact, it should populate non_persistent_facts as well
|
||||
self._variable_manager.set_nonpersistent_facts(target_host, result_item['ansible_facts'].copy())
|
||||
|
||||
if 'ansible_stats' in result_item and 'data' in result_item['ansible_stats'] and result_item['ansible_stats']['data']:
|
||||
|
||||
if 'per_host' not in result_item['ansible_stats'] or result_item['ansible_stats']['per_host']:
|
||||
|
||||
Reference in New Issue
Block a user