using values in group via pillar

Skip to first unread message

Jun 28, 2022, 9:17:08 AMJun 28
to Salt-users


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:
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

NdK ClanBO

Jul 13, 2022, 1:41:34 AMJul 13
to Salt-users
Hi Stefan.

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

    - 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 %}


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.

Reply all
Reply to author
0 new messages