Can I dynamically include multiple sls files using a pattern or a glob

57 views
Skip to first unread message

BKeep

unread,
Apr 29, 2017, 12:43:15 AM4/29/17
to Salt-users
Is there a way to include multiple state.sls files or pillar.sls files dynamically using regex or similar?

Currently in my pillars top file I have the standard for managing user secrets
base:
 
'* not G@os:win*':
   
- match: compound
   
- users.users
   
- users.remove

I want to try something different for managing my users but I don't know if I will be able to do it the way I am thinking. In sticking with the UNIX as the IDE philosophy, my thought is to name the files in a way that each is unique by having a separate file for each user instead of one large users.sls. This would allow using standard ls and grep to quickly see users sls files vs. using a huge users file.

An example naming convention would be like root-active.sls, bkeep-active.sls, tom-active.sls, susan-active.sls, barb-remove etc. This idea works fine, except going this route forces me to have 200 users.user-add includes in the pillars top file and mostly defeats the goal of not having a large file that is hard to skim names and whatnot.

Something like the below example is what I am after.
base:
 
'* not G@os:win*':
   
- match: compound
   
- users.*-active
   
- users.*-remove

Any ideas or comments are appreciated.

Regards,
Brandon

BKeep

unread,
May 8, 2017, 8:43:26 PM5/8/17
to Salt-users
This pretty much does what I wanted.
  '* not G@os:win*':
   
- match: compound
{% for file in salt['file.readdir']('/srv/pillar/users') %}
{% if file not in ('.', '..') %}
{% set user = file.split('.sls')[0] %}
   
- users.{{ user }}
{% endif %}
{% endfor %}

Regards,
Brandon

Mike Freitas

unread,
May 9, 2017, 9:39:14 AM5/9/17
to Salt-users
Hi Brandon,

You can also checkout Pillar Stack for even more flexibility in your pillar.


Mike
Reply all
Reply to author
Forward
0 new messages