-
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
Ability for pillar to read other pillar values #6955
Comments
Seems like a chicken and an egg problem to me -- I don't know how we could do this without multiple passes. However, @thatch45 thinks it might be possible but is not sure how to do it at this point. I've put this on the Approved for Future Release milestone until we find a good way to implement this. |
#4326 may be related. |
I've been thinking about this for a while. I should agree with @basepi . Pillar is a minion-specific data which is stored on the master and compiled on a minion. There could be a problem: how do I get a pillar data if that pillar is not associated with a minion? We can't switch compilation to the master side, obviously. And we can't say The only possible solution I see is to make something like
Probably we can complicate this a bit. Let's say we have
Thus, we define
Salt will make sure that defined path (e.g. database.info, without last .user/.password chunks) exists and it's a common file, then it will look through the file (database/info.sls) in order to find As i see this should work without any security issues. |
I just want to throw in my experience with this matter. I have a fairly simple use case. I need to setup a postgres DB, and setup an application that uses this DB, naturally both of these will have overlapping values and I would like to declare these in only one location. Normally I would simply declare the data in an agnostic 'settings' dict in the pillar and have the states manage it and both postgres state & application state reffer to the one value in the pillar. However, I have just begun to investigate using the salt formulas and these complicate the issue. In my case its the sentry formula and the postgresql formula but its another angle to this 'pillar in the pillar' problem and if the solution doesnt fix this, well. Then theres still a bigger problem :-/ |
I'm facing a similar issue which would really benefit from this feature. Wouldn't this pave the way to setting pillar data via salt states so that they can retroactively affect other related states too? |
Let me add my comment onto this, and an idea for implementation. The reason I want this is that I have a fairly complex pillar written in "#!py" for a customer. However, there is a minority of the content of that pillar, currently expressed as a dict declaration, which I would like that customer to edit. This would be vastly less error-prone if I could store that dict as a 2nd pillar in pure YAML. However, I can't because pillars can't refer to other pillars. My implementation idea is simple: load the pillars in the order given in pillar/top.sls. If a user wants a pillar to refer to another pillar, they need to get the ordering right themselves. |
I really need this feature since I need to assign pillars to minions depending on the environment variable which is (who guesses it) another pillar. Storing role/ environment information on minion-side in grains is UNSAFE and should NEVER be done. The salt docs mustn't recommend this either. I also don't have access to external pillar data in my pillar files. We really need a solution here. I don't see a salty solution for this problem yet. |
As a workaround I'm creating a YAML file with common data and serializing into a (Jinja) template variable as I do it in my formulas: https://github.com/bechtoldt/httpd-formula/blob/master/httpd/init.sls#L1 |
@bechtoldt you might find reclass helpful (http://reclass.pantsfullofunix.net/) i spent some time this weekend rolling out grains as a way to work around this. next i'll be playing with reclass. i keep reading that it provides a way around this limitation. |
@alienzrcoming I'm using salt.pillar.foreman for this but don't have access to it's within pillar SLS files. |
UPDATE: This is impossible approach at the moment because Jinja template is processed before Preserving pillar include orderI thought it already works by preserving order in which pillar files are loaded. The idea was simple:
Pillar example
Problem confirmedCurrently
|
I've first thought Something like this might even be an option: Either accumulate pillar-data (first process elements of the list |
I've done this using Puppet + hiera before, and was a tremendous win. |
There is a (workaround) solution!Recent updates in this issue pointed at loading variables by Jinja itself (which means ability to data in one Jinja file from another) - @wuxxin, thanks! For example:
It's not exactly accessing pillar values (because real pillar values are result of rendering).
Even if it is a workaround, the approach reduces the urgency of implementation. |
I was also hit by this. It seems all pillars are combined together and ordered based on alphabetical order. So I can access those which top-level field are before in alphabetical order, but not later. And this is despite me specifying the order in |
I take back. It does not seem to be by alphabetical order. |
FYI, I've created the PillarStack |
@uvsmtid: I found another (easier?) solution. Leave original file as it was: regular_yaml:
with_arbitrary:
structure:
- a
- b
- c In file you want to put include: {% import_yaml 'path/to/some_paramters.sls' as vars %}
variables_loaded_from_another_file: {{ vars }}
|
@morsik: Yes, it's less cumbersome! The only caution for those who employ examples above is that
The same documentation has examples of Bottom lineJinja + pure YAML (or JSON) provide decent workaround to the requested feature, but it does not extend into any SLS renderer combination. |
Maybe using libucl (BTW: very nice presentation about UCL in FreeBSD) would mitigate some of the problems. The parser can handle things like includes and reuse of assigned variables on its own. |
+1 on proper implementation |
FWIW, reclass handles this use case very gracefully, and I would recommend considering reclass if you need some keys to reference other keys - http://reclass.pantsfullofunix.net/operations.html#parameter-interpolation |
Do we have an example of what kind of output this feature should generate? Functional specs? Each issue asking for this feature is slightly different. I did some testing to replicate a simple system I had in a previous (homemade) config system: https://gist.github.com/hemebond/3b31f3ed5ba89dfc0af7655a498b8d2b |
FWIW, reclass does this perfectly, and has exactly what the primary use cases want out of the general idea. If you want pillar to be able to interpolate from other pillar, right now, the best way to do so is to use reclass as an ext pillar module. It works great, and actually vastly simplifies your use of pillar (eg for defaults, salt's setup for defining default pillars is really messy in comparison). EDIT: sorry, I didn't mean to sound like a broken record, I overlooked my previous comment immediately above the last, lol.. |
I thought reclass only interpolated variables that appeared higher in the hierarchy. Is that not the case? If reclass does everything people need for Pillar interpolation do we need to keep any of these tickets open? |
How then, in your opinion, Salt should handle pillar data, provided from a CLI (a.k.a pillar overrides, which are controlled by I'm busy preparing a PR with implementation of your solution and I stumbled upon this problems. |
@AndrewPashkin Beats me, I never got that complex. My Salt setups were relatively simple; I just joined this issue because I wanted a lot of re-use of variables. My ordering suggestion was a way to do "baby steps", and otherwise resolve an order-of-resolution issue which was blocking solutions. |
FWIW, reclass has the code to show us how to construct the tree and walk it. |
@jberkus, yes, I understand, but your idea implies, that order of when CLI pillars and external pillars are loaded, must also be defined. Otherwise it would be undefined behaviour, for example user would make some expectations, based on order of his pillars, but somebody could also provide CLI pillars and it would lead to unexpected results and so on. |
Makes sense. Is the ordering currently undefined? BTW, just so you know: the project which caused me to comment on this issue has been over for more than a year, so I won't be able to test any solution. |
@jberkus, currently external pillars are always loaded before regular ones and are reference-able from regular ones (I've mistaken in my past comment, |
Well, sounds like the order of load is defined, then. It's perfectly OK if that ordering is defined by Salt. It's just with the standard pillars where ordering is undefined. |
@jberkus, hm, yes, you are right, actually. |
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. |
salt could use reclass and easily provide this functionality. |
Thank you for updating this issue. It is no longer marked as stale. |
Yeah, @ketzacoatl, reclass (GH: madduck/reclass) is probably the best choice here. |
Yea, that's a question beyond me, though I don't think it needs to be made an external dependency. Salt could still make use of the code - it's clean, reliable, and robust. As a user, the experience is awesome. |
@ketzacoatl @0xf10e FYI saltclass (which is very similar to reclass) is now directly available in salt from version 2018.3.0. |
oh wow... so this is already done then.. we should close this ticket as complete.. no? |
Sweet, thanks for pointing this out for us, @bbinet! |
not fastest performance wise, but can do this by importing pillar as yaml pillar1.sls
/pillar/host1.sls
|
@perfecto25 this is something I proposed 8 years ago... and if you read this issue, you can find that this feature was added 5 years... that's quite gold shovel prize :P |
Hi, I have a number of states that could be greatly simplified if pillar could read other pillar values. One use case example is I have a "walt_warning" pillar value which i populate in all managed files. I have several pillar values that declare the entire contents of files which are referenced by jinja templates, and instead of having to populate each instances of this with the contents of the salt_warning value, it'd be much easier to just list it as {{ pillar['salt_warning'] }} in the pillar value itself.
Another example would be a situation where pillar declares values that are dependent on another pillar variable the declares the environment a system is in (eg test, staging, live), which is also declared in pillar.
Thanks in advance!
The text was updated successfully, but these errors were encountered: