-
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
State inclusion is limited #14899
Comments
Hmmm, I'm unsure of how we would do this. As you mentioned before, top level keys in YAML must be unique. I'm open to ideas about how this would look. |
The only thing I can think of is it you make include-something, and then we
|
Maybe something like this could work? I know this would look like a state, but that actually kind of makes sense, right? This is my id for an include of my test sls:
include:
- test
This is another id for an include of foo sls:
include:
- foo |
👍 if it isn't too difficult to implement I think that would be fine, but I have no idea where to stick that in right now. |
That is a decent idea. Will take some careful modifications of the state compiler, though, so it's not going to be straightforward (and it may be some time before we implement it). |
+1 for this, to have named |
I have never really worked with the Maybe someone with a bit more knowledge of See also: http://docs.saltstack.com/en/latest/ref/states/extend.html |
If I'm not mistaken, |
So, funny enough I was wrong about how the jinja include works, and it actually does exactly what I want. This will include the sls files in the order specified, from multiple file roots: Ensure myfile is managed:
file.managed:
...
{% include 'a/init.sls' %}
Ensure myservice is running:
service.running:
...
{% include 'b/init.sls' %} |
Ooh, good workaround. I'll still leave this open, as I think it would be something useful, but at least we have a good workaround for now. |
So, this workaround isn't wonderful. One issue is that normal includes allow you to define the include in multiple locations and it'll deduplicate the include. If you use a jinja include, it pulls all the states into the current scope, which means you'll get duplicates if you use the jinja include in more than one spot. It would be really nice to properly support this. It's a bit painful doing sequentially ordered states without it. |
I suppose the only way to truly achieve this is to split each part of the state into its own SLS files and do a nested set of includes that way. Here's a workaround that prevents duplicate states, but doesn't preserve order. {% set includes = [] %}
Ensure myfile is managed:
file.managed:
...
{% do includes.append('a') %}
Ensure myservice is running:
service.running:
...
{% do includes.append('b') %}
include: {{ includes | json }} |
I think includes in this situation would still be executed out of order,
|
Having multiple 'include' to order execution would be perfect! Cheers |
+1 for this, to have named include |
+1 for this, for now I'll go with the workaround... |
+1 for this, to have named include states also. |
I think the best option here might just be to concatenate the list of all includes found then perform execution of those. The only issue occurs when we think of the order of execution. I believe that can be fixed by appending some sort delimiter in the list, it would use similar code logic as that used in the requisite section. The delimiter would have to be invisible to the user but salt should be aware of 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. |
Any news on this issue? |
Any news on having this feature? :( |
Currently, in a state I can include other modules:
However, I'm doing ordered runs, and want to be able to define some states, then an include, then some more states, then another include:
This isn't possible since include is a yaml key and must be unique. It's possible to include the files explicitly via jinja:
{% include 'a/init.sls' %}
But this doesn't allow me to load a module from a different file_root without looping through the file_roots in opt, then checking to see if the file exists, then including it.
It would be nice if include works for multiple calls in a state file.
The text was updated successfully, but these errors were encountered: