using values in group via pillar

20 views
Skip to first unread message

stefa...@googlemail.com

unread,
Jun 28, 2022, 9:17:08 AM6/28/22
to Salt-users

Hello,

I'm using salt since a while but more or lesse for just very basic staff and just via state-files. Now I'm done with host specific pillars in this way: https://www.reddit.com/r/saltstack/comments/5b4l9v/comment/d9mqu1p/?utm_source=share&utm_medium=web2x&context=3
Is it somehow possible to use this in a group way, eg all which have the role webserver (definded in pillar) have defaults like pillar logs:/var/log/apache2 or all server that start with fw* should get this pillars, except there are more specific thing for the host (in pillars).

thanks in advance, best regards
Stefan

NdK ClanBO

unread,
Jul 13, 2022, 1:41:34 AM7/13/22
to Salt-users
Hi Stefan.

I think what you're trying to do is like what I handled in my pillar/top.sls :
-8<--
{% set host, domain = grains['id'].split('.', 1) %}
{% set hostbase = grains['id']|replace('.', '_') %}
{% set dom=domain|replace('.', '_') %}

base:
  '*':
    - default
{% if salt['pillar.file_exists']('hostdata/'+hostbase+'.sls') %}
    - hostdata.{{hostbase}}
{% endif %}

# File init.sls must be present even if empty!
# BUG: pillar.file_exists does not detect directories :(
{% if salt['pillar.file_exists'](dom+'/init.sls') %}
  '*.{{ domain }}':
    - {{ dom }} # init.sls contains the domain defaults
{% if salt['pillar.file_exists']("{0}/{1}".format(dom,host)+'.sls') %}
    - {{ dom }}.{{ host }} # Host-specific pillars
{% endif %}
{% endif %}

-8<--

You can have hostdata/minion_snake_id.sls for per-minion defaults, that gets overridden by domain-specific pillars, that gets overridden by hostname.sls in domain directory (I either place full minion_id in hostdata or just hostname.sls in domain directory).

You can extend it to consider extra roles, but IMVHO it's handled better from state files: pillars should just give the authoritative config. Remember that the only grain that's safe to use is 'id'.

I'm just a Salt noob, please  correct me if I'm wrong.

BYtE,
 Diego
Reply all
Reply to author
Forward
0 new messages