mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-05-06 13:22:48 +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:
@@ -35,6 +35,9 @@ class ActionModule(ActionBase):
|
||||
result = super(ActionModule, self).run(tmp, task_vars)
|
||||
|
||||
facts = dict()
|
||||
|
||||
cacheable = bool(self._task.args.pop('cacheable', False))
|
||||
|
||||
if self._task.args:
|
||||
for (k, v) in iteritems(self._task.args):
|
||||
k = self._templar.template(k)
|
||||
@@ -51,4 +54,5 @@ class ActionModule(ActionBase):
|
||||
|
||||
result['changed'] = False
|
||||
result['ansible_facts'] = facts
|
||||
result['ansible_facts_cacheable'] = cacheable
|
||||
return result
|
||||
|
||||
@@ -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