-
Notifications
You must be signed in to change notification settings - Fork 23.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add set_fact_persistent action and module. #26153
Conversation
The test
|
why not add a |
Mainly because this approach doesn't require changes to plugins/strategy/* |
using a 'cacheable' flag would be more flexible than the current 'set_fact' match, other modules could create non persistent/persistent facts |
@bcoca can add a cacheable Attribute to Task, and set it from set_fact.py (or normal.py) and check it in strategy set_fact module assumes all params passed to it are key=value pairs however, so adding a 'cacheable' arg to the module could cause conflicts (seemingly even 'args'). If we avoid the potential name conflict and dont add a module arg for skip_facts, then it will have to default to false and we need another module that could take a 'cacheable' arg. But at the moment, all other modules are already cacheable, but would still need a set_fact_persistent that enables cacheable and set_fact. Or we could make 'cacheable' a prohibited fact name to use with set_fact... |
anyone setting 'args' as a var is already creating issues for themselves, other 'raw' parameter modules allow options (see creates= in shell/command) so it would not be a first. my worry about introducing a new module is also that it introduces a new precedence step, while introducing a toggle between the 2 types of facts does not. |
Updated. Not sure if the behavior on regular set_fact is correct. Logic was updated so that set_fact always sets non_persistent_facts and if cacheable, also sets host_facts. That seems to do the right thing, but not sure about the details of the precedence. Without the change, the behavior when using caching and non-caching set_fact on the same fact name is a little odd. A fact set non caching, and then later set with caching, the non caching value wins because of the higher precedence of non_persistent facts. Adding to non persistent facts and host_facts seems to DWIM there, but unsure of consequences elsewhere. |
its odd, but it is documented, set_fact wins over 'actual facts' .. the real difference being cacheable/non-cacheable. I don't think this works well as task keyword as most tasks don't return facts, only module that return 'ansible_facts' do. |
So, just a '_ansible_fact_cacheable' in module/action return and checked by strategy? |
I like this approach. It would allow me to cache facts that are important to me, but probably not important enough to make upstream changes to a specific fact module and eliminate maintaining local changes to modules over the course of Ansible releases. |
Definitely gotta +1 a cacheable option for set_facts. |
+1 |
1 similar comment
+1 |
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.
We dont want to use 'ansible_facts_cacheable' result item or 'cacheable' arg as actual facts, so pop them out of the dicts.
* 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.
@@ -511,12 +511,14 @@ def parent_handler_match(target_handler, handler_name): | |||
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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't mess around in strategy often so I don't know if this is normal but,, why is the default here True but False everywhere else?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
because set_fact
is only module in which this was not true, all other 'ansible_facts' should be cacheable by default.
SUMMARY
Used just like set_fact, except facts set with set_fact_persistent
will be stored in the fact cache if fact caching is enabled.
set_fact only sets facts in the non_persistent_fact_cache, so they
are lost between invocations.
The implementations here are pretty much exact copies of set_fact.
The module likely needs to do that, but the action plugin could in theory
import set_fact and subclass it (all it needs is a different action name...)
ISSUE TYPE
COMPONENT NAME
modules/utilities/logic/set_fact.py
plugins/strategy/
plugins/action/
ANSIBLE VERSION
ADDITIONAL INFORMATION