How to execute SLS files in sorted order

If you need to ensure that your SLS files are executed in a sorted order, then simply use this init.sls file.

{% set dirpath = '/srv/salt' | path_join(slspath) %}

include:
{% for file in salt['file.readdir'](dirpath) | sort %}
{% if file | regex_match('^(\d+.+).sls

 
, ignorecase=True) %}
  - .{{ file | replace('.sls', '') }}
{% endif %}
{% endfor %}

 

Working with lists in Jinja2

Working with lists in Jinja2 is really simple if you are using the following trick.

{%- set vfs_objects = [] %}
{%- if share.recyclebin | to_bool %}
{%- set _ = vfs_objects.append('recycle') %}
...
{%- endif %}
{%- if share.audit | to_bool %}
{%- set _ = vfs_objects.append('full_audit') %}
...
{%- endif %}
vfs objects = {{ vfs_objects | join(' ') }}