Search code examples
automationsalt-project

How to use asterisk (*) in saltstack pillar function declaration in top.sls file?


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.


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.