github.com/nickadam/salt-talk

An intro to SaltStack

Software to automate [and document] the management and configuration of any infrastructure or application.

About Me

Nick Vissari

@nickadam
Work @ HoCo Public School System
Security Guy & DevSecOps Enthusiast

Sysadmins have to configure systems
Keeping track of things is hard
Documentation to the rescue!
  • Word docs
  • Text files
  • Uber 1337 h4x0r shell scripts
  • Talking to yourself on slack
  • Bookmarks to stack overflow answers
Infrastructure as code!
& track it all with git

wikipedia.org/wiki/Infrastructure_as_code


Lab/demo time!

github.com/nickadam/salt-talk/tree/master/lab
  1. Start environment
  2. Install salt master
  3. Install salt minions
  4. Accept keys
  5. Test connectivity

Install salt master


salt-talk/lab$ vagrant ssh master
$ sudo apt install curl
$ curl -L https://bootstrap.saltstack.com -o install_salt.sh
$ sudo sh install_salt.sh -P -M
        

Install salt minions


salt-talk/lab$ vagrant ssh minion1
$ sudo apt install curl
$ curl -L https://bootstrap.saltstack.com -o install_salt.sh
$ sudo sh install_salt.sh -P
        

Accept the keys

Test connectivity

Run commands using cmd.run
Errors are fun
Grains

Targeting minions

  • 'server*' = server1 server2 server3 server-fred
  • 'server?' = server1 server2 server3
  • 'server[1,3]' = server1 server3
  • 'server[1-3]' = server1 server2 server3
  • -L 'server1,server2'
  • -G 'role:worker' = whoever has the grain role=worker
  • -S '192.168.0.0/16' = whoever is in the subnet

Compound matchers

-C 'G@role:worker and
G@os_family:debian and
not *fred'
SaLt State file
xyz.sls

xyz:
  pkg.installed
            
or

xyz:
  cmd.script:
    - source: salt://xyz-installed.sh
        
Keep track of what you do

cd /srv
git config --global user.name "John Doe"
git config --global user.email johndoe@example.com
git init
        
/srv/salt/screenfetch/installed.sls

screenfetch:
  pkg.installed
        
Test it

...
/srv/salt/top.sls

base:
  'minion?':
    - screenfetch.installed
        

...
/srv/salt/go/installed.sh

#!/bin/bash
# Download and extract go
if [ ! -f "/usr/local/go/bin/go" ]
then
  cd /root
  wget -q https://dl.google.com/go/go1.14.linux-amd64.tar.gz
  tar -C /usr/local -xzf /root/go1.14.linux-amd64.tar.gz
  rm /root/go1.14.linux-amd64.tar.gz
fi
# Add go bin path to global profile
if ! grep /usr/local/go/bin /etc/profile >/dev/null
then
  echo export PATH=\$PATH:/usr/local/go/bin >> /etc/profile
fi
        
/srv/salt/go/installed.sls

go:
  cmd.script:
    - source: salt://go/installed.sh
        
/srv/salt/top.sls

base:
  'minion?':
    - screenfetch.installed
  'salt':
    - go.installed
        
/srv/salt/netdata/installed.sh

#!/bin/bash
if [ ! -f "/usr/sbin/netdata" ]
then
  bash <(curl -Ss https://my-netdata.io/kickstart.sh)
fi
        
/srv/salt/netdata/deps.sls

autoconf:
  pkg.installed
autoconf-archive:
  pkg.installed
autogen:
  pkg.installed
automake:
  pkg.installed
cmake:
  pkg.installed
gcc:
  pkg.installed
git:
  pkg.installed
libjudy-dev:
  pkg.installed
liblz4-dev:
  pkg.installed
libmnl-dev:
  pkg.installed
libssl-dev:
  pkg.installed
libuv1-dev:
  pkg.installed
make:
  pkg.installed
pkg-config:
  pkg.installed
uuid-dev:
  pkg.installed
zlib1g-dev:
  pkg.installed
        
/srv/salt/netdata/installed.sls

include:
  - netdata.deps
netdata:
  cmd.script:
    - source: salt://netdata/installed.sh
        
/srv/salt/top.sls

base:
  'minion?':
    - screenfetch.installed
  'salt':
    - go.installed
  'G@role:worker':
    - netdata.installed
        
/srv/pillar/top.sls

base:
  '*':
    - users
        
/srv/pillar/users.sls

users:
  nick: 30001
  tim: 30002
  jen: 30003
        
/srv/salt/users/init.sls

{% for user, uid in pillar.get('users', {}).items() %}
{{user}}:
  user.present:
    - uid: {{uid}}
{% endfor %}
        
becomes

nick:
  user.present:
    - uid: 30001
tim:
  user.present:
    - uid: 30002
jen:
  user.present:
    - uid: 30003
              

Summary

  • /srv/salt - what is deployed, how
  • /srv/salt/top.sls - where are states deployed
  • Git - who did what when
  • /srv/pillar - kinda secret store for data, great for complicated jinja stuff
  • /srv/pillar/top.sls - where the data goes

Extra bits

  • docs.saltstack.com
  • python, yaml, jinja are our friends
  • salt-ssh - clientless salt
  • salt mine - dynamic data from minions for minions
  • salt runners - convenient programs for the master

Thanks

Go forth and DevOps!
...and have fun!