Describe how you’d like your computers, and Salt will configure them. For example, I want Apache web server, with PHP and user homepages, on all my computers whose name starts with ‘web’.
To say the same in jargon: write your infrastructure as code, so that configuration management system, the single source of thruth, applies your states idempotently.
Prerequisites: we’re starting from a working master-slave setup.
Instructions to Slaves in Master /srv/salt/
Master gives instructions to slaves. On the master, these instructions are stored in /srv/salt/. You must create this folder.
$ sudo mkdir -p /srv/salt/
Create a hello world state.
$ sudoedit /srv/salt/hello.sls
The states (like hello.sls) are written in YAML. The indentation is two spaces. No, tabs will not work.
/tmp/hellotero.txt: file.managed: - source: salt://hellotero.txt
The source path “salt://” means master’s /srv/salt/ directory. So the master copy of the file salt://hellotero.txt is in master’s /srv/salt/hellotero.txt.
$ sudoedit /srv/salt/hellotero.txt
See you at http://TeroKarvinen.com
Apply State on All Slaves
You can apply a single state once on all slaves with
$ sudo salt '*' state.apply hello
Top.sls Applied Automatically
Salt can control your slaves while you sleep! Create a top.sls file, and slaves apply it periodically
$ sudoedit /srv/salt/top.sls
base: '*': - hello
If you don’t want to wait for half an hour, you can apply the top file immediately
$ sudo salt '*' state.highstate
Well done, you can now have Salt control your slaves while you sleep.