top file - manage states

The top file manages SLS state files for salt minions. It would be analogous to the puppet manifest site.pp, but is written in YAML which keeps things minimal and clean. Things are pretty well documented on but we can go over the basics to get you up and running.

If we don’t edit the configuration file /etc/salt/master, the default path for the top file and other SLS files is /srv/salt. You can change this in /etc/salt/master, looking for the following option:

    - /srv/salt

Create top.sls

For an example, lets create a simple top.sls to include an sls called cron to be included for all minions, and another named apache to only match minions with a hostname starting with web (,, etc.)

Note: These sls files do not yet exist, so a run with just this file will fail and tell you it can’t fine anything named cron or apache.

vi /srv/salt/top.sls

    - cron
    - apache

Create cron.sls and apache.sls

Now lets create these simple state files, later we’ll move them into their own directories and serve files from them.

vi /srv/salt/cron.sls


vi /srv/salt/apache.sls

    - name: httpd
    - name: httpd

Test top.sls

This command runs top file locally on your server which is useful for debugging and can be run from any minion:

salt-call state.highstate

This command from the salt master runs the top file across all minions.

salt '*' state.highstate

Test individual state SLS files

Test apache.sls from any minion.

salt-call state.sls apache

Run this from the master to push to all minions:

salt '*' state.sls apache

Run this from the master to push apache to all servers with an fqdn beginning with web.

salt 'web*' state.sls apache

Next, we’ll serve conf files from saltstack and automatically restart the associated service.