-
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
Trying to reference existing pillars in new pillars (both first-level and subdirectories/init.sls) leads to unexpected behaviour #51360
Comments
looks like there was this issue: #6955 which was closed with the inclusion of saltclass which solved this problem. another issue here: #4244 (comment) is a workaround to include other pillar data.. I think you are right though we need to define this more within the docs. ping @saltstack/team-core it seems based off the issues I read, referencing pillar in other pillar files is not entirely supported without using workarounds. Is this true on your end as well? if so I think we should document this with the workarounds, until we can add this capability. |
Thank you SO much. I was going crazy, here. I'll check out saltclass! I briefly was reading about it but couldn't really use it because my data source is in MySQL stored in formats that aren't exactly Salt-friendly (e.g. UUIDs are in BINARY(16), IPv4/IPv6 addresses are in VARBINARY(4) and VARBINARY(16) respectively, etc. - so I can't directly use the mysql module because there are necessary transformations). While I could probably do this with a "py" template, an ext_pillar seemed more appropriate/"clean". I technically don't even need to inherit pillars from parent pillars, though it'd be nice - I was just operating under the assumption that because my Pardon my insanity last night; to clarify the specific use case, there are some pillars that will be unique to every minion, but others that are shared for every minion (or most minions, with an overridden exception here and there) but you want to be able to enforce them from/keep private to the master. Roles and role-based strategy is an example of this; you don't want to trust a role to a grain because a machine shouldn't be able to decide or change its role, the saltmaster should. This is especially true of organizations with a global presence where some of the machines in remote locations may be liable to... well, political motivations outside the organization's influence. An alternative, at least in MY use case, would be to have a new type of fact/object, master-enforced grains ("rocks", I guess they could be called?) that would act as grains scope-wise (e.g. available to pillars) but would be enforced by the master and could not be changed by a minion. That way it's an ideal compromise between the policy enforcement of pillars while still being able to reference them in pillars - but this largely seems a redundancy of pillars, so the ROI of implementing such a new type would probably not be worth it. Pillars-in-pillars would definitely be beneficial to a very large number of users, though, I'd wager. Thanks again for looking into this! Sorry for the novel! I wanted to clarify my (admittedly exhausted) initial post on my reasoning behind this. |
Also throwing here for reference since it's where I got the opts['pillar'] thing from in the first place and it took me forever to find it again: #37905 (comment) . |
@johnnybubonic I'd avoid saltclass unless you want to deal with the open issues. The person who contributed it (@olivier-mauras) does not respond to mentions and has no activity on Github since June 2018 (life happens). If you want to go this route, it is worth looking at Also, there are other ext_pillar backends that try to solve the pillar inheritance problem in different ways (one example is Generally speaking, you need to consider the following factors:
For security, you would want to avoid assigning secrets to nodes based on untrusted data (anything that comes from a minion: grains, fileserver cache, etc. - the only trusted thing is For a highly dynamic infrastructure, reclass/saltclass is a bad fit because you need to create one file per node (although reclass has a workaround). If the scale is small and you have many snowflakes, then For high scale (thousands of nodes), the common advice is to minimize pillar usage (use it only to for sensitive data, or retrieve your secrets using the Vault Hope this helps. |
helps a bit, yeah; part of my issue is trying to maintain DRY while also wondering how the thing's going to scale - not by model, as i'm intentionally trying to design that in, but the resource usage for master(s). i just mostly wish there were a way to dynamically and conditionally assign pillars based on other pillars in the top file. i've gotten around it for now by implementing pillar matching in the pillar top, and that works well enough: {%- set saltpath = opts.pillar_roots[saltenv] -%}
base:
'ext_pillar_name:type:foo':
{%- set invtype = 'foo' %}
- match: pillar
- foo
'ext_pillar:type:bar':
{%- set invtype = 'bar' %}
- match: pillar
- bar
{%- for curpath in saltpath %}
{%- if salt['file.file_exists']('{0}/{1}/{2}.sls'.format(curpath, invtype, grains.id)) %}
'{{ grains.id }}':
- {{ invtype }}.{{ grains.id }}
{%- endif %}
{%- endfor %} and this lets me get done what i need to get done, but it... feels hacky. it was the most reliable way i could get it working, though. |
on that note, was |
It was recently documented and is available in See #46833 |
OH. it's in a FUTURE release! that explains it. thanks! that'll simplify some things! |
I seem to have the same problem still / again on 2019.2. ext_pillar_first is set to True but targetting using the external pillar's data in the pillar top file doesn't work:
@johnnybubonic 's last comment suggests this somehow should work, but even deleting minion cache doesn't seem to solve it |
@siliconsheep i think it's still only in the develop branch, i don't think it's in a release yet |
Oh, I assumed by the looks of #51403 you managed to find a way to do exactly the thing I'm trying to accomplish or were you using the develop branch then as well? Currently, I'm using pillarstack as a workaround, but would be nice to know if the original plan will work in the future as well :) |
@siliconsheep sorry for the delay - no, i had to completely redesign my approach; it's currently significantly less efficient/performant as a result, but it works at least. i never was able to get the above working reliably. |
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. |
keep open; we still want pillar referencing within pillars. :) |
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. |
stalebot, i JUST marked this as unstale yesterday. wat r u doin |
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. |
still valid |
Thank you for updating this issue. It is no longer marked as stale. |
Funny I stumbled upon this when a friend of mine tried We found another "workaround" for this if you just use the pillar dictionary: I was using this for years very successfully with highly complex pillar data (from a custom Netbox module and gitstack) because pillar and grains dictionaries are mentioned in a lot of Salt docs. But the "bug" or missing featue didn't hit me because I always ran ext_pillar after pillar_roots. 🙂 |
You guys are the real heroes. Add my name to the list of people that want something similar. https://www.reddit.com/r/saltstack/comments/k0h0tr/using_pillars_to_assign_pillars_in_the_pillar/ |
This is such a weird behavior. Is this a bug or feature? in pillar_roots
using a custom execution module which internally tries to reference the pillar via Being able to access previously set pillars from |
bump |
In case of IPAM or cloud provider solutions being used as One idea would be a setting similar to It seems solutions such as pillarstack could help with solving this outside of Salt's built in pillar merging functionality - however they are, in my opinion, not well documented. The project documentation on pillarstack mostly provides basic examples on including local pillar files, and community provided sample configurations do not hint as to how existing |
Description of Issue/Question
The documentation is not clear, and there are numerous issues on this repo about this.
What is the canonical, elegant way to access a pillar from a pillar?
I have an ext_pillar set up, and I have ext_pillar_first set to True in my master config.
I then need to further assign pillars based on what the pillars that are returned from ext_pillars are.
I've found that I can do this in a completely hacky and not at all proper way via opts['pillar']['ext_pillar_name'] (and such as a result from that dict) - in the pillar_roots top file with no issue.
But I need to consistently be able to access that same data in recursed pillars (e.g. accessing ext_pillar from
<pillar_root>/something/init.sls
, or even<pillar_root>/not_top.sls
which is called from<pillar_root>/top.sls
). When I try, it's a gamble if it works (presumably a cache? Though I have pillar cache disabled) or if I get this:jinja2.exceptions.UndefinedError: 'dict object' has no attribute 'pillar'
In full:
Please, please, please, for the love of my sanity - why can't I reliably access existing pillars in new pillars?
pillars.get('some:key')
does not work.salt['pillars.get']('some:key')
does not work.The only thing that DOES work (albeit half the time) is the opts[''] hack. Grains, as expected, work fine but you can't enforce those from the master.
The text was updated successfully, but these errors were encountered: