-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Fetching require data during salt states run, after previous states executed. #44778
Comments
@hackerwin7 I think what you might want is to use a combination of
|
@garethgreenaway Thanks your reply, the key problem is how can I get the run-time and dynamic result that
The |
@hackerwin7 ahh that makes more sense. Perhaps the orchastrate module will accomplish what you're trying to do? |
@garethgreenaway Thanks your advice very much!
However, a few puzzles appears:
As you see, first I want to use jinja to implement |
After reviewing my question, my key problem is that get a run-time value produced by the states in a single minion and single sls file.
|
@garethgreenaway Is there any flexible solution for this? I find this is very similar to me. |
I have similar problem to this, tough I don't know if there is possible workaround for my problem. |
same here. I need to create a user, create their ssh-keys, then read the pubkey and use it in a |
Found this issue when I was faced with the same problem. Creating a user with a formula and querying user data of the same newly created user in another formula during a highstate. Since the query happens when the highstate gets rendered the highstate will obviously fail with no data for the new user - since the user did not exist at that time. Getting dynamic results which depend on a previous salt states result in the renderer is impossible since everything gets rendered before the states gets executed. This has to be done when executing a state. Namely doing this with custom states. https://docs.saltstack.com/en/latest/ref/states/writing.html The only way to do this is by wrapping the states with your custom state modules defined in _states with the required logic. All you would need to do is for example
then call the state in the formula + sync custom states beforehand
This would allow one to create a new user and query its data in the same highstate and update kwargs with whatever is needed which one would pass to the original state which requires this data. If one does not want to wrap their states then the only sane way to achieve this is by having some central datasource which gets updated via custom external pillars so that all states in a highstate work with the same required data. |
I'm wondering if this is the same issue I'm seeing FOO:
location:
{% if grains['id'].endswith('.fmt1.foo.com') %}
site: fmt1
{% else %}
site: unknown
{% endif %}
nameservers:
{% if salt['pillar.get']('FOO:location:site', 'unknown') == 'fmt1' %}
{% if salt['network.in_subnet']('1.2.12.0/23') %}
- '1.2.12.16'
{% endif %}
- '1.2.13.16'
- '1.2.14.16'
{% else %}
# WARNING we don't know which sites name servers to use.
- '8.8.8.8'
- '8.8.4.4'
{% endif %} and querying # salt 'bar.fmt1.foo.com' pillar.get nameservers
bar.fmt1.foo.com:
- 1.2.8.16
- 8.8.8.8
- 8.8.4.4
# salt 'bar.fmt1.foo.com' pillar.get FOO:location:site
bar.fmt1.foo.com:
fmt1 |
Same here: a custom exec module is fetching a file from internet, and it returns its name and location. I should use the returned data to install such package during the next state. |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. If this issue is closed prematurely, please leave a comment and we will gladly reopen the issue. |
reopen, still seems like an issue on another note, not sure how ansible solves it, but I know you can use output of previous ansible commands in subsequent commands. |
Thank you for updating this issue. It is no longer marked as stale. |
Yeah ansible is designed different that way. Afaik Salt lacks such a feature and it would be really helpful to have it. |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. If this issue is closed prematurely, please leave a comment and we will gladly reopen the issue. |
been another month, please reopen... |
Thank you for updating this issue. It is no longer marked as stale. |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. If this issue is closed prematurely, please leave a comment and we will gladly reopen the issue. |
been another month, please reopen... |
Thank you for updating this issue. It is no longer marked as stale. |
don't bother stalebot, this is still an issue. |
any update on this? facing the same issue |
I think this sep describe this issue problem saltstack/salt-enhancement-proposals#33 |
Just wanted to post a workaround that we are using in our production system which has worked fairly well.
The salt master has this configured in the reactor states:
The reactor file itself looks like this and injects the custom variables into pillar for the next state to use:
Whichever state was defined in the first event message, will then be executed on the same minion. That state can then run an execution module before rendering and gather the info from the previous state run. |
I'm also facing this problem - in my case, globbing to pkg.removed. (i'm trying to cleanup no longer needed rpms). What I want is a a salt state that gets all the packages with pkg.list_pkgs, grep out a pattern (glob would also be acceptable here), and then pkg.removed that list. |
Hey, i just want to let my experience here and hope that it helps some of you. You have different ways how to accomplish your goal.
my .sls:
Additionally important here in this powershell case is to escape the double quotes in the command that should be executed and the option "shell" to tell cmd.run to use powershell. Here is the output:
Our debug state shows us that it is working. I post an other special solution for mysql_query.run in a second post. :) |
As mentioned above here now a other special way for mysql_query.run. Story of .sls: Description of this code: Let's go. my .sls:
Sadly i don't have an output to this highstate. But it worked for me at year 2020/21. |
HI,
I am writing some salt states into SLS file and encounter a simple common case is that:
In a sls file, if state.2 need state.1 generated data.
such as:
other-states need {{ dir_name }} value to continue to execute.
After viewing the following links:
Jinja variables are set before the state will be executed
#12470
Is there any way to fit this case by using salt states or other flexible solutions for this.
The text was updated successfully, but these errors were encountered: