Slide 1

Slide 1 text

Getting Started with Salt

Slide 2

Slide 2 text

Peter Baumgartner Founder, Lincoln Loop

Slide 3

Slide 3 text

What is SaltStack?

Slide 4

Slide 4 text

“SaltStack delivers a dynamic infrastructure communication bus used for orchestration, remote execution, configuration management and much more.”

Slide 5

Slide 5 text

No content

Slide 6

Slide 6 text

SaltStack is Configuration Management

Slide 7

Slide 7 text

Configuration Management

Slide 8

Slide 8 text

root@server:~# ls /etc/nginx/nginx* /etc/nginx/nginx.conf Before Configuration Management

Slide 9

Slide 9 text

root@server:~# ls /etc/nginx/nginx* /etc/nginx/nginx.conf /etc/nginx/nginx.conf.OLD Before Configuration Management

Slide 10

Slide 10 text

root@server:~# ls /etc/nginx/nginx* /etc/nginx/nginx.conf /etc/nginx/nginx.conf.OLD /etc/nginx/nginx.conf.BAK Before Configuration Management

Slide 11

Slide 11 text

root@server:~# ls /etc/nginx/nginx* /etc/nginx/nginx.conf /etc/nginx/nginx.conf.OLD /etc/nginx/nginx.conf.BAK /etc/nginx/nginx.conf.20130617.bak Before Configuration Management

Slide 12

Slide 12 text

No content

Slide 13

Slide 13 text

After Configuration Management

Slide 14

Slide 14 text

Version control your servers Self-documenting Repeatable Reusable Benefits

Slide 15

Slide 15 text

SaltStack is Remote Execution

Slide 16

Slide 16 text

Run command(s) against remote server(s) e.g. Fabric, Capistrano, Func Remote Execution

Slide 17

Slide 17 text

Deploy your code Run one-off scripts Critical package updates System monitoring/alerting https://github.com/lincolnloop/salmon Remote Execution Examples

Slide 18

Slide 18 text

Why Choose SaltStack?

Slide 19

Slide 19 text

Python YAML Jinja2 Familiar Tools

Slide 20

Slide 20 text

Great Documentation (>800 pages) Insanely responsive (IRC, GitHub) Backed by for-profit org Community

Slide 21

Slide 21 text

Why Choose SaltStack?

Slide 22

Slide 22 text

Why Not Choose SaltStack?

Slide 23

Slide 23 text

Young Project Moves Fast Not SSH (SSH support soon) https://github.com/saltstack/salt/issues/5913 https://github.com/saltstack/salt/issues/5914 Caution

Slide 24

Slide 24 text

Let’s Learn Salt!

Slide 25

Slide 25 text

First... a vocabulary lesson

Slide 26

Slide 26 text

Chef: knife, recipe, cookbook Puppet: terminus, metaparameters Ansible: playbook, inventory Everything is Terrible

Slide 27

Slide 27 text

Chef: knife, recipe, cookbook Puppet: terminus, metaparameters Ansible: playbook, inventory Salt might be the worst offender... Everything is Terrible

Slide 28

Slide 28 text

Mas•ter ˈmastər (noun) Server that manages the whole stack (auth, states, pillars)

Slide 29

Slide 29 text

Min•ion ˈminyən (noun) A server controlled by the master

Slide 30

Slide 30 text

State stāt (noun) A declarative representation of system state. (how you want the minion configured)

Slide 31

Slide 31 text

Grain grān (noun) Static information about a minion (RAM, CPUs, OS, etc.)

Slide 32

Slide 32 text

Pil•lar ˈpilər (noun) Variables for one or more minions (ports, file paths, configuration parameters)

Slide 33

Slide 33 text

No content

Slide 34

Slide 34 text

Top File täp fīl (noun) Matches states or pillars to minions

Slide 35

Slide 35 text

High•state hīstāt (noun) All the state data for a minion

Slide 36

Slide 36 text

No content

Slide 37

Slide 37 text

Let’s Really Get Started

Slide 38

Slide 38 text

Binaries for most distros Pip install (for bleeding edge) http://bootstrap.saltstack.org (it probably does what you want) Installation Options

Slide 39

Slide 39 text

root@master:~# apt-get install salt-master Master Server ...or run master-less

Slide 40

Slide 40 text

# apt-get install salt-minion # echo "salt 10.10.1.1" >> /etc/hosts # salt-key -a minion.lincolnloop.com Accept the minion key on the master Point minion to the master Minion

Slide 41

Slide 41 text

Write Your First State

Slide 42

Slide 42 text

nginx: pkg.installed /srv/salt/mystate.sls (or /srv/salt/mystate/init.sls) Install a Package

Slide 43

Slide 43 text

Create your Top File

Slide 44

Slide 44 text

base: myserver.lincolnloop.com: - mystate /srv/salt/top.sls The Top File

Slide 45

Slide 45 text

Highstate!

Slide 46

Slide 46 text

# salt 'myserver.lincolnloop.com' state.highstate # salt-call state.highstate ...or pull from the minion Push from the master Highstate ...or master-less # salt-call state.highstate --local

Slide 47

Slide 47 text

[INFO ] Executing state pkg.installed for nginx [INFO ] Executing command "dpkg-query --showformat='${Status} ${Package} $ {Version}\n' -W" in directory '/' [INFO ] Executing command 'grep-available -F Provides -s Package,Provides -e "^.+$"' in directory '/' [INFO ] Executing command 'apt-get -q update' in directory '/' [INFO ] Executing command 'apt-get -q -y -o DPkg::Options::=--force-confold -o DPkg::Options::=--force-confdef install nginx' in directory '/' [INFO ] Executing command "dpkg-query --showformat='${Status} ${Package} $ {Version}\n' -W" in directory '/' [INFO ] Executing command 'grep-available -F Provides -s Package,Provides -e "^.+$"' in directory '/' [INFO ] Installed Packages: libgeoip1 changed from absent to 1.4.8+dfsg-2 nginx changed from absent to 1.1.19-1 libxml2 changed from absent to 2.7.8.dfsg-5.1ubuntu4 nginx-common changed from absent to 1.1.19-1 libfreetype6 changed from absent to 2.4.8-1ubuntu2 nginx-full changed from absent to 1.1.19-1 xml-core changed from absent to 0.13 geoip-database changed from absent to 20111220-1 libxslt1.1 changed from absent to 1.1.26-8ubuntu1 libjpeg-turbo8 changed from absent to 1.1.90+svn733-0ubuntu4 libgd2-noxpm changed from absent to 2.0.36~rc1~dfsg-6ubuntu2 sgml-base changed from absent to 1.26+nmu1ubuntu1 libjpeg8 changed from absent to 8c-2ubuntu7 ,,,

Slide 48

Slide 48 text

[INFO ] Loading fresh modules for state activity local: ---------- State: - pkg Name: nginx Function: installed Result: True Comment: The following packages were installed/updated: nginx. Changes: libgeoip1: { new : 1.4.8+dfsg-2 old : } nginx: { new : 1.1.19-1 old : } libxml2: { new : 2.7.8.dfsg-5.1ubuntu4 old : } nginx-common: { new : 1.1.19-1 old : } libfreetype6: { new : 2.4.8-1ubuntu2 old : } nginx-full: { new : 1.1.19-1 old : } ...

Slide 49

Slide 49 text

No content

Slide 50

Slide 50 text

No content

Slide 51

Slide 51 text

Leveling Up Your States

Slide 52

Slide 52 text

pete: user.present: - shell: /bin/bash - home: /home/pete - groups: - sudo Create a User

Slide 53

Slide 53 text

pete: user.present: - shell: /bin/bash - home: /home/pete - groups: - sudo ssh_auth.present: - user: pete - source: salt://pete.pub - require: - user: pete Add an SSH Key

Slide 54

Slide 54 text

[email protected]/ipmb/mysite.git: git.latest: - rev: develop - target: /usr/local/src/mysite - require: - pkg: git-core Checkout a Repo

Slide 55

Slide 55 text

python manage.py syncdb --noinput: cmd.run: - cwd: /usr/local/src/mysite - require: - git: [email protected]/me/mysite.git Run Arbitrary Commands

Slide 56

Slide 56 text

Over 50 built-in pip, virtualenv mysql, postgres services, files, cron ...or build your own (in Python) Built-in States

Slide 57

Slide 57 text

Using Pillars

Slide 58

Slide 58 text

Pil•lar ˈpilər (noun) Variables for one or more minions (ports, file paths, configuration parameters)

Slide 59

Slide 59 text

mysite: - branch: develop /srv/pillar/mysite.sls Example Pillar

Slide 60

Slide 60 text

base: 'myserver.lincolnloop.com': - mysite /srv/pillar/top.sls Pillar Top File

Slide 61

Slide 61 text

base: '*': - default '*.lincolnloop.com': - lincoln_loop 'os:Ubuntu': - match: grain - pkgs.ubuntu /srv/pillar/top.sls Advanced Pillar Top File

Slide 62

Slide 62 text

[email protected]/ipmb/mysite.git: git.latest: - rev: {{ pillar.mysite.branch }} - target: /usr/local/src/mysite - require: - pkg: git-core Adding Pillars to a State

Slide 63

Slide 63 text

[email protected]/ipmb/mysite.git: git.latest: - rev: {{ pillar.mysite.get('branch', 'master') }} - target: /usr/local/src/mysite - require: - pkg: git-core Setting a Default

Slide 64

Slide 64 text

redis_maxmemory: {{ (grains.mem_total * 0.5)|int }}mb Using Grains in a Pillar

Slide 65

Slide 65 text

/etc/redis.conf: file.managed: - template: jinja - source: salt://packages/redis_server/redis.conf.jinja - defaults: maxmemory: {{ pillar.get('redis_maxmemory', '64mb') }} Using Pillars in Files

Slide 66

Slide 66 text

daemonize yes pidfile /var/run/redis.pid port 6379 bind 127.0.0.1 maxmemory {{ maxmemory }} ... /srv/salt/redis_server/redis.conf.jinja Using Pillars in Files

Slide 67

Slide 67 text

Salt-cloud Custom Modules Scheduler Renderers Returners Advanced Topics

Slide 68

Slide 68 text

Tips & Tricks

Slide 69

Slide 69 text

output_mode: mixed Tips & Tricks

Slide 70

Slide 70 text

Jinja2 is powerful Don't go nuts Tips & Tricks

Slide 71

Slide 71 text

Update often ...and review the change log Tips & Tricks

Slide 72

Slide 72 text

Tips & Tricks Test before you deploy Make friends with Vagrant or Docker

Slide 73

Slide 73 text

Thank you! Questions? Peter Baumgartner http://lincolnloop.com @ipmb