Fundamentals
Master
A central Salt daemon from which commands can be issued to listening minions.
Minion
A server running a Salt minion daemon which can listen to commands from a master and perform the requested tasks. Generally, minions are servers which are to be controlled using Salt.
Targeting
Specifying which minions should run a command or execute a state by matching against hostnames, or system information, or defined groups, or even combinations thereof
Module
Functions called by the salt command that perform specific tasks.
There are many types of modules:
Salt-key
Executes simple management of Salt server public keys used for authentication between masters and minions.
Grain
A key-value pair which contains a fact about a system, such as its hostname, network addresses.
SLS
Stands for Salt State
State
The definition of the desired state of salt minions, States comprise of single or multiple salt modules.
State Module
A module which contains a set of functions (things that need to be done).
YAML
Is a human-readable data format.
Why use Salt?
What can Salt do?
Who uses Salt now?
Group Activity: What can you use Salt for?
Master and Minions
Salt Master
Controller of your Salt Minions
Diagram here
Salt Minion
Allows for a Salt Master to control a server
Key Management
Diagram here
Salt Modules
In a Nutshell
Philosophy
Languages
Add User in Ruby
user "fred" do
supports :manage_home => true
comment "Fred Flintstone"
uid 4000
home "/home/fred"
shell "/bin/zsh"
end
group "wheel" do
action :modify
members "fred"
append true
end
group "storage" do
action :modify
members "fred"
append true
end
Add user in YAML
fred:
user.present:
- fullname: Fred Flintstone
- shell: /bin/zsh
- home: /home/fred
- uid: 4000
- gid: 4000
- groups:
- wheel
- storage
Architecture
Management
Communications
Templating
Advantages of Salt
salt-bootstrap
salt-bootstrap
salt-bootstrap is the easiest method to install SaltStack.
Download salt-bootstrap
wget -O install_salt.sh http://bootstrap.saltstack.org
Run salt-bootstrap
sh install_salt.sh
This example will install the minion, but -h show the help
Example flags
sh install_salt.sh -M -A localhost
This will install the Master and Minion (and configure it) all on the same machine.
Salt Keys
Salt Keys
Salt Keys manages which machines are allowed / not allowed to communicate with the Salt Master
salt-key
The -A flag will accept all pending keys
Verify installation
salt-master --versions-report
If installed correctly, you will see something like:
Salt: 2014.1.0
Python: 2.7.6 (default, Mar 22 2014, 22:59:56)
Jinja2: 2.7.2
M2Crypto: 0.21.1
msgpack-python: 0.3.0
msgpack-pure: Not Installed
pycrypto: 2.6.1
PyYAML: 3.10
PyZMQ: 14.0.1
ZMQ: 4.0.4
Lab
Execution Modules
Execution Modules
Execution modules are used when calling modules directly from the command line.
salt '*' user.add fred uid gid groups home shell
test.ping
This is the most basic module you can run. It simply connects to the targeted minion(s) and returns True if that minion responds.
salt '*' test.ping
minion1:
True
minion2:
True
There is no matching state module for test.ping.
test.ping Demo
Running Commands
Running arbitrary commands can come in handy for one time operations. This is done with the cmd.run module.
Execution Example
salt webservers cmd.run "service apache2 restart"
State Example
touches_foo:
cmd.run:
- name: touch /tmp/foo
- creates: /tmp/foo
Date Command Demo
Your Turn!
State Modules
State Modules
State modules are used when calling state.sls or highstate agains t a minion.
salt '*' state.sls myslsfile
fred:
user.present:
- fullname: Fred Jones
- shell: /bin/zsh
- home: /home/fred
- uid: 4000
- gid: 4000
- groups:
- wheel
- storage
- games
Installing a Package
Package installations are abstracted by Salt. You don't have to invoke a specific yum or apt module, but a pkg module.
State Example
salt '*' pkg.install vim
Execution Example
install_vim:
pkg.installed:
- name: vim
Package names can still be different between distributions. (ie. apache2 and httpd)
Starting a Service
Starting services is done with the service module.
Execution Example
salt '*' service.start apache2
State Example
run_apache2:
service:
- running
- name: apache2
- enable: True
Service names can still be different between distributions. (ie. apache2 and httpd)
Installing sysstat Demo
Restart SSH Demo
Your Turn!
hint
vim_install:
pkg.installed:
- name: vim
Grains
A grain is a piece of data related directly to a Salt Minion. You can view all grains related to a node with the grains.items module.
salt minion1 grains.items
You can target minions using data in grains. This example will target all your CentOS servers with a test.ping.
salt -G 'os:CentOS' test.ping
Grains Demo
Lab
Write your own state file to...
A massive thanks to the content dev team...
Allen Oster
Bruce Stringer
Chris Caillouet
Chris Old
Eric Hernandez
Jason Swindle
Justin Phelps
Kenneth Wilke
Victor Palma