Salt State with Multiple SLS Files

One salt state can have multiple SLS files. Other files are included from init.sls, so you can just use folder name to run the whole multi file state.

Following this article requires fluency in command line and basics of Salt. You should have Salt version Helium or later.
Consider a lamp state. In its current form, it will install Apache and MySQL. The folder /srv/salt/lamp/ contains the whole lamp module, including sls state files and templates.

$ pwd
/srv/salt/lamp
$ ls
apache.sls  init.sls  mysql.sls

The init file uses include() to apply (run) the other states.

$ cat init.sls
#!pyobjects
include('lamp/apache', 'lamp/mysql')

When running the module, you can just call “lamp” state, which applies init.sls, which uses include() to apply the two other state files apache.sls and mysql.sls.

$ sudo salt-call --local state.sls lamp --state-output=mixed
local:
 Name: apache2 - Function: pkg.installed - Result: Clean
 [..]
 Name: mysql-server - Function: pkg.installed - Result: Clean
 [..]
Succeeded: 9
Failed:    0
 [..]

By putting related files into the same state folder, you can keep your files nice and tidy.

Posted in Uncategorized | Tagged , , , , , , | Comments Off on Salt State with Multiple SLS Files

Comments are closed.