Zohar Arad. © 2015
Features that make SaltStack stand out from the crowd include:
Salt States are the heart of SaltStack's engine, and define the final state in which our server should be configured.
nginx:
pkgrepo.managed:
- ppa: nginx/stable
- require_in:
- pkg: nginx
pkg.installed:
- version: 1.6.2
service.running:
- enable: True
- require:
- pkg: nginx
/etc/nginx/sites-available/www.mysite.com:
file.managed:
- source: salt://packages/nginx/sites-available/www.mysite.com
- template: jinja
- require:
- pkg: nginx
/etc/nginx/sites-enabled/www.mysite.com:
file.symlink:
- target: salt://packages/nginx/sites-available/www.mysite.com
- require:
- file: /etc/nginx/sites-available/www.mysite.com
SaltStack's Pillars are the way we define variables that can be passed on to our Salt State files
Pillars help us create reusable, generic states with custom, user-defined variables.
# Pillar File
nginx:
- stable: 1.6.2
- edge: 1.7.3
# State File
{% set nginx = pillar.get('nginx', {}) -%}
nginx:
pkg.installed:
- version: {{ nginx['stable'] }}
Salt Grains are useful bits of information about the underlying OS we're trying to configure, such as OS type (Ubuntu or RedHat), CPU Arch., network and hostnames and even user-defined information (such as roles).
Like Salt Pillars, Grains help us define generic Salt States that target multiple configuration targets and scenarios.
apache:
pkg.installed:
{% if grains['os'] == 'RedHat'%}
- name: httpd
{% elif grains['os'] == 'Ubuntu' %}
- name: apache2
{% endif %}
# nginx configuration
server {
listen 80;
server_name {{ grains['id'] }} {{ grains['id'] | replace('www','') }};
root /var/www/mysite.com/public;
}
With out States, Pillars and Grains in place, we can now see how learn about Master, Minions and applying our configuration to target servers.
Top files (top.sls) are the entry point of our States and Pillars configuration
Since everything in SaltStack is a file, Top files serve as the entry point from which we can target which minions will receive which parts of States and Pillars configuration tree.
/srv/salt/states - top.sls /salt - minion.sls - master.sls /nginx - init.sls /repos - ubuntu.sls
base: '*': - salt.minion 'salt-master*': - salt.master '^(lb|web).(qa|prod).loc$': - match: pcre - nginx 'os:Ubuntu': - match: grain - repos.ubuntu
/src/salt/pillars - top.sls /salt - minion.sls - master.sls /www.mysite.com - init.sls
base: '*': - salt.minion 'salt-master*': - salt.master '^web.(qa|prod)': - match: pcre - www.mysite.com
Remote execution is basically the entry point to control minion state via state files or run arbitrary commands on a subset of registered minions
This is useful because it provides us with a fine-grained control over each minion using a very simple CLI.
# tell minions to go into "high-state"
$ salt 'www*' state.highstate
# upgrade SSH server on all minions
$ salt '*' cmd.run 'aptitude install sshd=1.1.0~ubuntu-1.1.2'
SaltStack is more than just a configuration manager. So far we covered the bare basics to familiarize ourselves with Salt.
For more advanced topics, including environment-based configs, scheduling and job managemnet, check out docs.saltstack.com