Run Salt Command Locally
You can run Salt commands locally, and see the result immediately. This is useful for practice, testing and quick setup. The same Salt functions work in both Linux and Windows, so if you can't remember how to stop a daemon in Windows, this can help, too.
The most important state functions are pkg, file, service, user and cmd.
Salt is normally used to control large number of slave computers over the network. This is handled in my other Salt articles.
Install Salt Slave
To install Salt slave daemon in Debian or Ubuntu
$ sudo apt-get update
$ sudo apt-get -y install salt-minion
You can check that you have it
$ sudo salt-call --version
pkg.installed - An Application Should Be Installed
$ sudo salt-call --local -l info state.single pkg.installed tree
$ sudo salt-call --local -l info state.single pkg.removed tree
file.managed - There Should be a File
In Linux, all settings are just text files.
$ sudo salt-call --local -l info state.single file.managed /tmp/hellotero
$ sudo salt-call --local -l info state.single file.managed /tmp/moitero contents="foo"
$ sudo salt-call --local -l info state.single file.absent /tmp/hellotero
service.running - A Daemon is Running
This function, service.running, is often used to automatically restart the daemon when settings should be changed.
$ sudo salt-call --local -l info state.single service.running apache2 enable=True
$ sudo salt-call --local -l info state.single service.dead apache2 enable=False
user.present - User Should Exist
$ sudo salt-call --local -l info state.single user.present terote08
$ sudo salt-call --local -l info state.single user.absent terote08
cmd.run - Running a Command
$ sudo salt-call --local -l info state.single cmd.run 'touch /tmp/foo' creates="/tmp/foo"
- You must make it idempotent (only run it when changes are needed).
- creates, unless, onlyif
- Use file, service or user instead of cmd.run
Instructions
$ sudo salt-call --local sys.state_doc
Adminstrivia
This article has been updated after publishing.
Icon "thin-client-solid" from Clarity Icons by WMware, received under the MIT license.