Question

I am new to saltstack automation and was wondering if there is a way to use asterisk (*) in saltstack pillar function declaration. Let me explain you all the details.

My pillar root for prod environment is

======
# grep -i pillar_root -A3 /etc/salt/master 
pillar_roots:
  prod:
    - /srv/pillar
======

I have top.sls file in /srv/pillar directory and the content of the file is given below.

======
# cat /srv/pillar/top.sls
prod:
  '*':
    - user.avatar_user
    - user.avatar_sudo_user
======

I will be adding *.sls files in /srv/pillar/user/ directory. However, please let me know if there is a way like this

======
prod:
  '*':
    - user.*
======

Thus, I won't need to add corresponding sls entries in top.sls.

Was it helpful?

Solution

You can't use the syntax you're wanting.

You could use jinja to shell out and list any files in that directory. That would probably look something like this: Contents of /srv/pillar/top.sls:

{% user_pillars = salt['cmd.run']('ls /srv/pillar/user*').split() %}

prod:
  '*':
{% for dir in user_pillars %}
    - {{ dir }}
{% endfor %}

I haven't tested this exact code, but it should be close to that.

OTHER TIPS

You could make a user/init.sls file, which explicitly includes the rest of the user files in its directory. Then all you would need to do in the top.sls file is include:

prod:
  '*':
    - user
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top