Tutorial — Salt
Tutorial¶
The Salt system setup is amazingly simple, as this is one of the central design
goals of Salt. Setting up Salt only requires that the Salt master be
running and the Salt minions point to the master.
- master
- The Salt master is the central server that all minions connect to. You
run commands on the minions through the master and minions send data
back to the master (unless otherwise redirected with a returner). It is started with the
salt-master program. - minion
- Salt minions are the potentially hundreds or thousands of servers that
you query and control from the master.
Installing Salt¶
As of this writing packages for Salt only exist for Arch Linux, but rpms and
debs will be available in the future (contributions welcome).
Instructions by operating system
Installing on Arch Linux ¶
The Arch Linux Salt package is available in the Arch Linux AUR (if you like
Salt vote for it on the Arch Linux AUR):
https://aur.archlinux.org/packages.php?ID=47512
For help using packages in the Arch Linux AUR:
Installing on Debian or Ubuntu ¶
Providing a .deb installer is on our short-list of things to do; until then
this is the best way to install Salt on Debian and Ubuntu systems:
-
Install the prerequisite packages:
aptitude install python-setuptools python-yaml python-crypto python-m2crypto cython libzmq-dev
Note
Installing on Ubuntu Lucid (10.04 LTS)
The ZeroMQ package is available starting with Maverick but it is not
yet available in Lucid backports. Fortunately, Chris Lea has made a
ZeroMQ PPA available. Install it before installing Salt:aptitude install python-software-properties add-apt-repository ppa:chris-lea/zeromq aptitude update aptitude install libzmq-dev
-
Grab the latest Python ZeroMQ bindings:
easy_install pyzmq
-
Install Salt:
easy_install –install-layout=deb https://github.com/downloads/thatch45/salt/salt-0.9.2.tar.gz
Please take note of the --install-layout=deb flag. This is important
for a functioning installation of Salt.
Installing from the source tarball ¶
- Download the latest source tarball from the GitHub downloads directory for
the Salt project: https://github.com/thatch45/salt/downloads - Untar the tarball and run the setup.py as root:
tar xvf salt-0.9.2.tar.gz cd salt-0.9.2 python2 setup.py install
Salt dependencies¶
This is a basic Python setup, nothing fancy. Salt does require a number of
dependencies though, all of which should be available in your distribution’s
packages.
- Python 2.6
- pyzmq – ZeroMQ Python bindings
- M2Crypto – Python OpenSSL wrapper
- YAML – Python YAML bindings
- PyCrypto – The Python cryptography toolkit
Optional Dependencies:
- gcc – dynamic Cython module compiling
Configuring Salt¶
Salt configuration is very simple. The default configuration for the
master will work for most installations and the only requirement for
setting up a minion is to set the location of the master in the minion
configuration file. The configuration files will be installed to
/etc/salt and are named after the respective components,
/etc/salt/master and /etc/salt/minion.
To make a minion check into the correct master simply edit the
master variable in the minion configuration file to reference
the master DNS name or IPv4 address.
See also
For further information consult the configuration guide.
Running Salt¶
-
Start the master in the foreground (to daemonize the process, pass
the -d flag):salt-master
-
Start the minion in the foreground (to daemonize the process, pass
the -d flag):salt-minion
See also
Arch Linux init scripts¶
/etc/rc.d/salt-master start /etc/rc.d/salt-minion start
Manage Salt public keys¶
Salt manages authentication with RSA public keys. The keys are managed on the
master via the salt-key command. Once a minion
checks into the master the master will save a copy of the minion key. Before
the master can send commands to the minion the key needs to be "accepted".
-
List the accepted and unaccepted salt keys:
salt-key -L
-
Accept a minion key:
salt-key -a <minion id>
or accept all unaccepted minion keys:
salt-key -A
See also
Order your minions around¶
Now that you have a master and at least one minion
communicating with each other you can perform commands on the minion via the
salt command. Salt calls are comprised of three main components:
salt '<target>' <function> [arguments]
See also
target¶
The target component allows you to filter which minions should run the
following function. The default filter is a glob on the minion id. E.g.:
salt '*' test.ping salt '*.example.org' test.ping
Targets can be based on minion system information using the grains system:
salt -G 'os:Ubuntu' test.ping
See also
Targets can be filtered by regular expression:
salt -E 'virtmach[0-9]' test.ping
Finally, targets can be explicitly specified in a list:
salt -L foo,bar,baz,quo test.ping
function¶
A function is some functionality provided by a module. Salt ships with a large
collection of available functions. List all available functions on your
minions:
salt '*' sys.doc
Here are some examples:
Show all currently available minions:
salt '*' test.ping
Run an arbitrary shell command:
salt '*' cmd.run 'uname -a'
See also
arguments¶
Space-delimited arguments to the function:
salt '*' cmd.exec_code python 'import sys; print sys.version'
Table Of Contents
- Introduction to Extending Salt
- Modules
- Grains
- Returners
- State Enforcement
- Salt Runners
- Renderers
- Python client API
- Salt File Server
Search
Enter search terms or a module, class or function name.