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 , , , , , , | Leave a comment

Leave a Reply

Your email address will not be published. Required fields are marked *

*

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

  • Picks

  • Boxing Clock for AndroidOcton8 Diving T-ShirtsShaking Tower Panda Android GameLearn Chinese with Android
  • Student projects