Please implement static pillars
Hi,
grains are often used for things that they aren't really optimal for (e.g. roles) solely because grains are the only user definable data source that can be referenced almost everywhere. Static pillars that would, essentially, only be Python dictionaries with immutable data in them would allow people to match on pillars in a variety of places or solve things such as mine data being unavailable in pillars (cf. #21403)
Thanks!
+1
Unless I'm misunderstanding what you're meaning, this is exactly what pillars are, outside of external pillars (which are the dynamic version). Anything using flat files in /srv/pillar/ on the master is static.
Or via ext pillar if you want to use python as well.
@techhat they are maybe not aware about salt pillar targetting via -I or compound matching ?
please also note that https://github.com/saltstack/salt/pull/23846 just came in.
@techhat @kiorky
This request basically boils down to matching by pillar in a pillar top.sls. Let's say I want to assign different roles to minions and then distribute credentials tied to a specific role. Setting the roles in grains is a security leak, as minions could fake a role. This leaves setting roles in pillars, but now I'd have to match on the role, which is defined in pillar, to get the complete pillar for the minion. This is a chicken and egg problem, so @babilen had the idea of being able to have a 'static' set of pillars, which is already available during the compile time of pillar's top.sls, so matchers like I@roles:dbserver can be used in it.
Another possiblity would be to do it similar to how the C precompiler does with macros and compile pillar in multiple runs until all references are resolved (while detecting circular references).
Aha! That makes more sense. Thanks for the clarification, @mbrgm.
I have to admit I don't know which route seems better, but maybe people will begin requiring matching on pillars in the static pillar, so we need another stage etc. I slightly lean towards multiple runs as the way to go, but I'm not familiar enough with how and where pillar gets compiled to substantiate that opinion... just a gut feeling.
Am 19.05.2015 um 19:56 schrieb Joseph Hall [email protected]:
Aha! That makes more sense. Thanks for the clarification, @babilen.
— Reply to this email directly or view it on GitHub.
@mbrgm what you want here is an ext pillar.
eg: https://github.com/makinacorpus/makina-states/blob/master/mc_states/pillar/mc_pillar.py which calls https://github.com/makinacorpus/makina-states/blob/master/mc_states/modules/mc_pillar.py
@kiorky Ok, this would take the configuration completely out of the file-based pillar. That's one option, of course. Don't you think there should still be an option for keeping what's possible inside the file-based pillar?
I would much prefer if this could be kept as simple as possible (i.e. file based pillar). It would allow users to manage their roles easily in pillars and also use cases such as the linked issue to allow people to use mine functions in pillars.
@babilen What's your preferred method? Would you rather create a static pre-pillar or recurse on the pillar compilation to resolve all references? I'm not sure if a static pre-pillar can eliminate all use cases where people would start requiring pillar-matching in the pre-pillar, requiring a pre-pre-pillar and so on.
My idea was to define pillars that use only terminal symbols and therefore don't require any recursive evaluation because no further "expansion" is needed.
They are simply "static".
Trying to converge on a completely evaluated pillar feels like we would be opening a can of worms that'll plague us forever to be honest.
@mbrgm not at all. For example, if you are looking more specifically on the mc_pillar one, it takes another yaml file as input (https://github.com/makinacorpus/makina-states/blob/master/files/database.sls is a sample)
We match our states with pillars from our cmdb: pillar.get('cmdb', {}).get('product') to assign a product/role and cmdb:status:prod*' to assign an environment in top.sls. We cannot use the same method to assign pillar data to our hosts since you cant use pillars to assign pillars.
This would be an excellent feature!
+1
Another usecase would be the definition of "pillar redirects" in which lookups to values in the static pillar would be allowed in the "non-static" pillar bit. That would allow for much better semantic organisation of pillars in that one could easily keep relevant data in one place and reference it from multiple places without having to change any states.
Maybe this approach would be helpful for someone. We have data.sls in pillar assigned to all hosts in top.sls. Content of data.sls is:
{% set files = [] %}
# Load pillar from host/.sls
{% if grains['id'] is defined %}
{% do files.append("host/" + grains['id'] + ".sls") %}
{% endif %}
# Load pillar from host/.sls if not loaded above
{% if grains['cluster'] is defined %}
{% do files.append("host/" + grains['cluster'] + ".sls") %}
{% endif %}
{% include files ignore missing %}
It try to load pillar from file host/fqdn.sls and if not exist then from host/cluster.sls.
Grain cluster is our custom grain module which strip numbers from fqdn.
Our pillar top.sls is very short and clean. Pillar load with data.sls can include other pillars or just containt all required data for minion.
@msciciel Thanks for sharing! At the moment I can't figure out how your approach could be used to match on pillar in pillars (as this is one of the things I hope to get accomplished by using static pillars). Can it be done?
@mbrgm We are using below structure to set pillar based on another pillar:
{% yaml_load 'cluster/web.sls' as vars %}
{% if vars.role == 'sth' %}
some: variable
{% endif %}
Maybe this will be helpful.