SlideShare a Scribd company logo
1 of 37
Download to read offline
Understanding Salt
Modular Sub-Systems and Customization
About Me (Jason Denning)
• DevOps Engineer
• SaltStack user for ~ 3 years
• SaltStack Certified Engineer #2
• AWS Certified Architect
• OSS Advocate (first Linux install ~ 1998)
• Pythonista
• jasondenning on GitHub / @jason_denning on Twitter
● Provide analytics and
marketing/segmentation tools for
mobile app developers
● Hosted backend APIs available world-
wide
● Lots of traffic
● Big fans of SaltStack
● upsight.com
Frustratingly Flexible
• Salt is extremely flexible and extensible
• Highly modular / easy to customize
• Can be difficult (at first) to know where your custom code should
go
• Occasionally confusing nomenclature
• Pillar
• Grains
• Mine
• Reactor
• ...
But once you know your way around..
...Salt’s pretty awesome
• Easy to customize
• Scalable
• Secure
• Doesn’t suffer from the Pareto Principal (80% rule)
This Talk
You’ll (hopefully) understand:
• When to use different functionality
• How all the pieces fit together
• How to get started customizing Salt
• Where to go next
Salt’s not Configuration Management
• Salt is a remote execution framework
• Run arbitrary code on remote hosts
• Tools to make this easy and flexible
• Configuration Management is just a common use-case
• Originally intended to be a tool for managing cloud-based
infrastructure
Remote Execution 101
Basic remote execution:
$ ssh jason@myhost "ls /home/jason"
it_worked.txt
Multiple hosts?
$ for h in myhost1 myhost2 myhost3;
> do ssh jason@myhost "ls /home/jason";
> done
Remote Execution 101
Ok, but what if:
• I want to run it on 100 hosts?
• My login credentials are different on some hosts?
• I actually want to do something with the output?
• I want to do this many times?
Remote Execution 102
How about a script?
#!/bin/bash
# Make sure your SSH config (~/.ssh/config) is setup!
command=$1
host_list=$2
for h in host_list; do
ssh "$h" "$command"
done
# FIXME: Add output handling
# FIXME: Add error handling
# FIXME: Add logging
# TODO: FIND A BETTER WAY TO DO THIS!!!!
Looks like we need:
A script that can handle:
● Executing arbitrary commands
● ...on one or more remote hosts
● …with a sane way to get the output (STDOUT? Write a file?
Text output? JSON? YAML??)
● …and graceful error handling
● …and logging
● …and authentication
● …and everything else I haven't thought of yet!
And then we realize..
● We only want to run a command if the host is in a particular
state...
● the command is different for some hosts because they have a
different OS...
● we need to configure host X before we configure host Y...
● we want to generate a file from a template, using data from an
external database
● we need to keep that external data secret
You want me to maintain a 5,000 line BASH Script?
I’m convinced - let’s use a framework
This is why Salt has so many modular subsystems:
• Each type of component scratches a particular itch (there’s
some overlap)
• ⇒ Modular
• Someone is inevitably going to want something slightly different
• ⇒ Extensible
• We’re almost always going to want things like error handling
• ⇒ One framework instead of several mini-frameworks
Salt Basics
• A host can be a “master”, “minion”, “masterless”, or any combination
• a master can instruct minions to run code (via ‘salt’ cmd)
• a minion can trigger actions on itself using code/configuration
stored on its master (via ‘salt-call’ cmd)
• a minion can run in isolation, called “masterless” (via ‘salt-call’)
• a single machine can run both master and minion daemons
The point: Some subsystems run on the master, some on the minion
The Event Sub-System
Salt transfers commands and other data (including files)between
hosts via the Event Sub-System.
• Publish/Subscribe message queue (based on ZeroMQ)
• Master can publish messages on minion queues, and vice-versa
• Code execution on the minion is triggered via Event messages
• Output is sent back to the master from the minion in the same
fashion
• Messages are encrypted, and authenticated with Salt’s Public
Key Infrastructure (PKI)
• Reactor: Watches the message queue on the master, and
triggers code execution when it sees specific events
How Salt Works (simplified)
$ salt minion1 cmd.run
Salt Master
<do stuff>
minion1
Master Message Bus
(zmq / RAET)
Message
(Event)
Message
(Event)
Minion Message Bus
(zmq / RAET)
Message
(Event)
Message
(Event)
<Encrypted>
Code Execution Sub-Systems
• Execution Modules (a.k.a. “modules”): Code that executes on
the minion
• Runner Modules: Code that executes on the master
• State Modules: Code that executes on the minion, depending
on the current state of the host (typically utilize execution
modules)
Code Execution: CLI
• ‘salt’ command: (from master) instruct minion(s) to invoke an
execution module, which executes code on the minion
• ‘salt-call’ command: (from minion) invoke an execution module,
which executes code on the minion
• ‘salt-run’ command: (from master) invoke a runner module,
which executes code on the master
Data Sub-Systems
• Pillar: Data which is passed to a particular minion via the master
• Pillar Modules: Code that runs on the master which
generates Pillar data
• Grains: Data which is set directly on the minion
• Grains Modules: Code that runs on the minion which
generates Grains data
• Mine: Data collected from minion(s) which is stored on the
master, and made available to all other minions
Major Subsystems: Output Handling
• Output Modules: Format output from the CLI
• e.g. text (human-readable), YAML, JSON
• Returner Modules: Send output to external data-stores
• e.g. syslog, MySQL, etcd
• Note: Minions always return output to the master on the
Event bus, regardless of whether Returner modules are
used or not
SLS Files
• Human-readable files, with the .sls extension
• Processed by the Renderer subsystem to create data structures
that are understood by other sub-systems
• Most users interact with Salt via SLS files
• Renderer Modules: Convert SLS files into usable data
structures (execute on both master and minion)
• Composable (e.g. Jinja + YAML)
• Can access Pillar and Grains data
Targeting Minions
• A salt-master can target minions based on the minions’ ids,
Grains, or Pillar data
• States and Pillar data are assigned to via the Master Tops sub-
system (typically, this is just a file, called top.sls)
• Salt-SSH targets hosts (which aren’t running the minion
daemon) via the Roster sub-system
Other Modular Sub-Systems
• Auth : Enable external authentication systems
• Fileserver: File storage backends used by the master
• Wheel: Used to manage the master’s configuration
• Net-API: Access the master via the web
New in 2015.2:
• Engine: Long-running code on either master or minion
• Beacons: Code running on minions, used to translate external
events to the Event bus
More Stuff!?!?
• Salt Cloud: Manage cloud (IaaS) infrastructure
• Salt SSH: Apply salt states on hosts without a minion daemon,
via SSH
• Salt Virt: Manage virtual hosts and hypervisors
• Proxy-Minions: Manage “dumb” hardware, such as network
hardware
That’s a lot of sub-systems!
Let’s Get Customizin’
• First, make sure that you actually need to write code
• http://salt.readthedocs.org/en/latest/ref/modules/all/index.html
• http://salt.readthedocs.org/en/latest/ref/states/all/index.html
• … etc.
• https://github.com/saltstack/salt-contrib
• Look at existing module code:
• https://github.com/saltstack/salt/tree/2015.2/salt/modules
• https://github.com/saltstack/salt/tree/2015.2/salt/states
• … etc.
Custom Execution Modules
# _modules/hello_world.py
‘’’
This comment will print if you run $ salt-call sys.doc hello
‘’’
__virtualname__ = ‘hello’
def world():
‘’’ Prints “Hello World!” - this will print if you run $salt-call sys.doc hello.world’’’
print(“Hello World!”)
Custom Execution Modules
• Need to determine if the module can run on this minion?
• write a function called “__virtual__()”
• if __virtual__() returns False, the module will not be
available
• Useful if your code has external dependencies
• Need a “private” function?
• Prefix the function name with an underscore
• i.e. _this_is_invisible_to_the_user()
• Any function that doesn’t begin with an underscore will be
callable
Custom Execution Modules - Imports
# A useful pattern if you need to import an external library
try:
import foomodule
HAS_FOO = True
except ImportError:
HAS_FOO = False
def __virtual__():
‘’’Only load the execution module if we could import foomodule’’’
if HAS_FOO:
return True
else:
return False
Accessing Other Modules
• When Salt loads your module, it will create a couple of magic
dicts, just like in SLS files
• __salt__ : use to call other execution modules
• e.g. __salt__[‘cmd.run’](“ls /”)
• __grains__ : use to access grains
• e.g. minion_id = __grains__[‘id’]
Custom State Modules
• Much like execution modules
• Need to return a dict with this format:
{ ‘result’: True,
‘comment’: “Info about the state execution”,
‘changes’: { ‘old’: ‘the state before function was applied’,
‘new’: ‘state after the function was applied’
}
}
• ‘result’ should be True if the state is correct, False if there was
an error, or None if this was a test run
Custom State Modules - Tips
• State functions must accept a ‘name’ argument, at minimum
• Enable test mode! ($ salt-call state.sls mystate.foo test=True)
• Write a function called “mod_init(low)” which accepts the Low
State Data Structure to do one-time setup and initialization
• If you want to enable the ‘watch’ requisite, write a function called
“mod_watch()” - see the service state for a good example
Example State
From the documentation:
http://docs.saltstack.com/en/latest/ref/states/writing.html#example-state-module
Recap
• Salt makes it easy to run custom code on your infrastructure,
with lots of icing
• Lots of modular sub-systems, but they’re useful!
• Write custom code once, run many times
• No 5,000 line BASH scripts!
Now we can run whatever code we want!
Thanks!
Questions?
salt@jasondenning.com
GitHub: jasondenning
Twitter: @jason_denning

More Related Content

What's hot

Salty OPS – Saltstack Introduction
Salty OPS – Saltstack IntroductionSalty OPS – Saltstack Introduction
Salty OPS – Saltstack IntroductionWalter Liu
 
Lifecycle Management with Foreman
Lifecycle Management with ForemanLifecycle Management with Foreman
Lifecycle Management with ForemanJulien Pivotto
 
Salt Stack pt. 2 : Configuration Management
Salt Stack pt. 2 : Configuration ManagementSalt Stack pt. 2 : Configuration Management
Salt Stack pt. 2 : Configuration ManagementUmberto Nicoletti
 
Saltconf 2016: Salt stack transport and concurrency
Saltconf 2016: Salt stack transport and concurrencySaltconf 2016: Salt stack transport and concurrency
Saltconf 2016: Salt stack transport and concurrencyThomas Jackson
 
PuppetCamp Sydney 2012 - Building a Multimaster Environment
PuppetCamp Sydney 2012 - Building a Multimaster EnvironmentPuppetCamp Sydney 2012 - Building a Multimaster Environment
PuppetCamp Sydney 2012 - Building a Multimaster EnvironmentGreg Cockburn
 
Jesse Olson - Nagios Log Server Architecture Overview
Jesse Olson - Nagios Log Server Architecture OverviewJesse Olson - Nagios Log Server Architecture Overview
Jesse Olson - Nagios Log Server Architecture OverviewNagios
 
Nagios Conference 2012 - Mike Weber - Failover
Nagios Conference 2012 - Mike Weber - FailoverNagios Conference 2012 - Mike Weber - Failover
Nagios Conference 2012 - Mike Weber - FailoverNagios
 
Running at Scale: Practical Performance Tuning with Puppet - PuppetConf 2013
Running at Scale: Practical Performance Tuning with Puppet - PuppetConf 2013Running at Scale: Practical Performance Tuning with Puppet - PuppetConf 2013
Running at Scale: Practical Performance Tuning with Puppet - PuppetConf 2013Puppet
 
Pulsarctl & Pulsar Manager
Pulsarctl & Pulsar ManagerPulsarctl & Pulsar Manager
Pulsarctl & Pulsar ManagerStreamNative
 
Red Hat Satellite 6 - Automation with Puppet
Red Hat Satellite 6 - Automation with PuppetRed Hat Satellite 6 - Automation with Puppet
Red Hat Satellite 6 - Automation with PuppetMichael Lessard
 
Automated MySQL failover with MHA: Getting started & moving past its quirks
Automated MySQL failover with MHA: Getting started & moving past its quirksAutomated MySQL failover with MHA: Getting started & moving past its quirks
Automated MySQL failover with MHA: Getting started & moving past its quirksColin Charles
 
Steamlining your puppet development workflow
Steamlining your puppet development workflowSteamlining your puppet development workflow
Steamlining your puppet development workflowTomas Doran
 
Auto infra with_foreman_katello
Auto infra with_foreman_katelloAuto infra with_foreman_katello
Auto infra with_foreman_katelloSachin Ghai
 
Containerizing Network Services - Alon Harel - OpenStack Day Israel 2016
Containerizing Network Services - Alon Harel - OpenStack Day Israel 2016Containerizing Network Services - Alon Harel - OpenStack Day Israel 2016
Containerizing Network Services - Alon Harel - OpenStack Day Israel 2016Cloud Native Day Tel Aviv
 
Monitoring of OpenNebula installations
Monitoring of OpenNebula installationsMonitoring of OpenNebula installations
Monitoring of OpenNebula installationsNETWAYS
 
SaltConf14 - Ryan Lane, Wikimedia - Immediate consistency with Trebuchet Depl...
SaltConf14 - Ryan Lane, Wikimedia - Immediate consistency with Trebuchet Depl...SaltConf14 - Ryan Lane, Wikimedia - Immediate consistency with Trebuchet Depl...
SaltConf14 - Ryan Lane, Wikimedia - Immediate consistency with Trebuchet Depl...SaltStack
 
Making MySQL Administration a Breeze - A look into a MySQL DBA's toolchest
Making MySQL Administration a Breeze - A look into a MySQL DBA's toolchest Making MySQL Administration a Breeze - A look into a MySQL DBA's toolchest
Making MySQL Administration a Breeze - A look into a MySQL DBA's toolchest Lenz Grimmer
 
[TechTalks] Learning Configuration Management with SaltStack (Advanced Concepts)
[TechTalks] Learning Configuration Management with SaltStack (Advanced Concepts)[TechTalks] Learning Configuration Management with SaltStack (Advanced Concepts)
[TechTalks] Learning Configuration Management with SaltStack (Advanced Concepts)Blazeclan Technologies Private Limited
 
What's new in MySQL 5.5? FOSDEM 2011
What's new in MySQL 5.5? FOSDEM 2011What's new in MySQL 5.5? FOSDEM 2011
What's new in MySQL 5.5? FOSDEM 2011Lenz Grimmer
 

What's hot (20)

Salty OPS – Saltstack Introduction
Salty OPS – Saltstack IntroductionSalty OPS – Saltstack Introduction
Salty OPS – Saltstack Introduction
 
Lifecycle Management with Foreman
Lifecycle Management with ForemanLifecycle Management with Foreman
Lifecycle Management with Foreman
 
Salt Stack pt. 2 : Configuration Management
Salt Stack pt. 2 : Configuration ManagementSalt Stack pt. 2 : Configuration Management
Salt Stack pt. 2 : Configuration Management
 
Saltconf 2016: Salt stack transport and concurrency
Saltconf 2016: Salt stack transport and concurrencySaltconf 2016: Salt stack transport and concurrency
Saltconf 2016: Salt stack transport and concurrency
 
PuppetCamp Sydney 2012 - Building a Multimaster Environment
PuppetCamp Sydney 2012 - Building a Multimaster EnvironmentPuppetCamp Sydney 2012 - Building a Multimaster Environment
PuppetCamp Sydney 2012 - Building a Multimaster Environment
 
Jesse Olson - Nagios Log Server Architecture Overview
Jesse Olson - Nagios Log Server Architecture OverviewJesse Olson - Nagios Log Server Architecture Overview
Jesse Olson - Nagios Log Server Architecture Overview
 
Nagios Conference 2012 - Mike Weber - Failover
Nagios Conference 2012 - Mike Weber - FailoverNagios Conference 2012 - Mike Weber - Failover
Nagios Conference 2012 - Mike Weber - Failover
 
Running at Scale: Practical Performance Tuning with Puppet - PuppetConf 2013
Running at Scale: Practical Performance Tuning with Puppet - PuppetConf 2013Running at Scale: Practical Performance Tuning with Puppet - PuppetConf 2013
Running at Scale: Practical Performance Tuning with Puppet - PuppetConf 2013
 
Pulsarctl & Pulsar Manager
Pulsarctl & Pulsar ManagerPulsarctl & Pulsar Manager
Pulsarctl & Pulsar Manager
 
Red Hat Satellite 6 - Automation with Puppet
Red Hat Satellite 6 - Automation with PuppetRed Hat Satellite 6 - Automation with Puppet
Red Hat Satellite 6 - Automation with Puppet
 
Automated MySQL failover with MHA: Getting started & moving past its quirks
Automated MySQL failover with MHA: Getting started & moving past its quirksAutomated MySQL failover with MHA: Getting started & moving past its quirks
Automated MySQL failover with MHA: Getting started & moving past its quirks
 
Steamlining your puppet development workflow
Steamlining your puppet development workflowSteamlining your puppet development workflow
Steamlining your puppet development workflow
 
Auto infra with_foreman_katello
Auto infra with_foreman_katelloAuto infra with_foreman_katello
Auto infra with_foreman_katello
 
OMD and Check_mk
OMD and Check_mkOMD and Check_mk
OMD and Check_mk
 
Containerizing Network Services - Alon Harel - OpenStack Day Israel 2016
Containerizing Network Services - Alon Harel - OpenStack Day Israel 2016Containerizing Network Services - Alon Harel - OpenStack Day Israel 2016
Containerizing Network Services - Alon Harel - OpenStack Day Israel 2016
 
Monitoring of OpenNebula installations
Monitoring of OpenNebula installationsMonitoring of OpenNebula installations
Monitoring of OpenNebula installations
 
SaltConf14 - Ryan Lane, Wikimedia - Immediate consistency with Trebuchet Depl...
SaltConf14 - Ryan Lane, Wikimedia - Immediate consistency with Trebuchet Depl...SaltConf14 - Ryan Lane, Wikimedia - Immediate consistency with Trebuchet Depl...
SaltConf14 - Ryan Lane, Wikimedia - Immediate consistency with Trebuchet Depl...
 
Making MySQL Administration a Breeze - A look into a MySQL DBA's toolchest
Making MySQL Administration a Breeze - A look into a MySQL DBA's toolchest Making MySQL Administration a Breeze - A look into a MySQL DBA's toolchest
Making MySQL Administration a Breeze - A look into a MySQL DBA's toolchest
 
[TechTalks] Learning Configuration Management with SaltStack (Advanced Concepts)
[TechTalks] Learning Configuration Management with SaltStack (Advanced Concepts)[TechTalks] Learning Configuration Management with SaltStack (Advanced Concepts)
[TechTalks] Learning Configuration Management with SaltStack (Advanced Concepts)
 
What's new in MySQL 5.5? FOSDEM 2011
What's new in MySQL 5.5? FOSDEM 2011What's new in MySQL 5.5? FOSDEM 2011
What's new in MySQL 5.5? FOSDEM 2011
 

Viewers also liked

Getting started with salt stack
Getting started with salt stackGetting started with salt stack
Getting started with salt stackSuresh Paulraj
 
Integration testing for salt states using aws ec2 container service
Integration testing for salt states using aws ec2 container serviceIntegration testing for salt states using aws ec2 container service
Integration testing for salt states using aws ec2 container serviceSaltStack
 
Test driven infrastructure avec Docker
Test driven infrastructure avec DockerTest driven infrastructure avec Docker
Test driven infrastructure avec DockerSéven Le Mesle
 
Using SaltStack to orchestrate microservices in application containers at Sal...
Using SaltStack to orchestrate microservices in application containers at Sal...Using SaltStack to orchestrate microservices in application containers at Sal...
Using SaltStack to orchestrate microservices in application containers at Sal...Love Nyberg
 
SaltStack - An open source software story
SaltStack - An open source software storySaltStack - An open source software story
SaltStack - An open source software storySaltStack
 
SaltStack For DevOps, Free Sample
SaltStack For DevOps, Free SampleSaltStack For DevOps, Free Sample
SaltStack For DevOps, Free SampleAymen EL Amri
 
A user's perspective on SaltStack and other configuration management tools
A user's perspective on SaltStack and other configuration management toolsA user's perspective on SaltStack and other configuration management tools
A user's perspective on SaltStack and other configuration management toolsSaltStack
 

Viewers also liked (8)

Getting started with salt stack
Getting started with salt stackGetting started with salt stack
Getting started with salt stack
 
Integration testing for salt states using aws ec2 container service
Integration testing for salt states using aws ec2 container serviceIntegration testing for salt states using aws ec2 container service
Integration testing for salt states using aws ec2 container service
 
Test driven infrastructure avec Docker
Test driven infrastructure avec DockerTest driven infrastructure avec Docker
Test driven infrastructure avec Docker
 
Using SaltStack to orchestrate microservices in application containers at Sal...
Using SaltStack to orchestrate microservices in application containers at Sal...Using SaltStack to orchestrate microservices in application containers at Sal...
Using SaltStack to orchestrate microservices in application containers at Sal...
 
Salt stack
Salt stackSalt stack
Salt stack
 
SaltStack - An open source software story
SaltStack - An open source software storySaltStack - An open source software story
SaltStack - An open source software story
 
SaltStack For DevOps, Free Sample
SaltStack For DevOps, Free SampleSaltStack For DevOps, Free Sample
SaltStack For DevOps, Free Sample
 
A user's perspective on SaltStack and other configuration management tools
A user's perspective on SaltStack and other configuration management toolsA user's perspective on SaltStack and other configuration management tools
A user's perspective on SaltStack and other configuration management tools
 

Similar to Understanding salt modular sub-systems and customization

Deployment of WebObjects applications on CentOS Linux
Deployment of WebObjects applications on CentOS LinuxDeployment of WebObjects applications on CentOS Linux
Deployment of WebObjects applications on CentOS LinuxWO Community
 
Running CentOS on the Facebook fleet
Running CentOS on the Facebook fleetRunning CentOS on the Facebook fleet
Running CentOS on the Facebook fleetDavide Cavalca
 
Owning computers without shell access 2
Owning computers without shell access 2Owning computers without shell access 2
Owning computers without shell access 2Royce Davis
 
Puppet Camp NYC 2014: Build a Modern Infrastructure in 45 min!
Puppet Camp NYC 2014: Build a Modern Infrastructure in 45 min!Puppet Camp NYC 2014: Build a Modern Infrastructure in 45 min!
Puppet Camp NYC 2014: Build a Modern Infrastructure in 45 min!Puppet
 
Deploying to Ubuntu on Linode
Deploying to Ubuntu on LinodeDeploying to Ubuntu on Linode
Deploying to Ubuntu on LinodeWO Community
 
Debugging webOS applications
Debugging webOS applicationsDebugging webOS applications
Debugging webOS applicationsfpatton
 
SecurityFest-22-Fitzl-beyond.pdf
SecurityFest-22-Fitzl-beyond.pdfSecurityFest-22-Fitzl-beyond.pdf
SecurityFest-22-Fitzl-beyond.pdfCsaba Fitzl
 
Deployment Strategy
Deployment StrategyDeployment Strategy
Deployment StrategyMongoDB
 
Owning computers without shell access dark
Owning computers without shell access darkOwning computers without shell access dark
Owning computers without shell access darkRoyce Davis
 
Deploying PHP on PaaS: Why and How?
Deploying PHP on PaaS: Why and How?Deploying PHP on PaaS: Why and How?
Deploying PHP on PaaS: Why and How?Docker, Inc.
 
Deployment Strategies (Mongo Austin)
Deployment Strategies (Mongo Austin)Deployment Strategies (Mongo Austin)
Deployment Strategies (Mongo Austin)MongoDB
 
unit 2 confinement techniques.pdf
unit 2 confinement techniques.pdfunit 2 confinement techniques.pdf
unit 2 confinement techniques.pdfRohitGautam261127
 
Building with Virtual Development Environments
Building with Virtual Development EnvironmentsBuilding with Virtual Development Environments
Building with Virtual Development EnvironmentsOscar Merida
 
[HES2013] Virtually secure, analysis to remote root 0day on an industry leadi...
[HES2013] Virtually secure, analysis to remote root 0day on an industry leadi...[HES2013] Virtually secure, analysis to remote root 0day on an industry leadi...
[HES2013] Virtually secure, analysis to remote root 0day on an industry leadi...Hackito Ergo Sum
 
Oracle WebLogic Diagnostics & Perfomance tuning
Oracle WebLogic Diagnostics & Perfomance tuningOracle WebLogic Diagnostics & Perfomance tuning
Oracle WebLogic Diagnostics & Perfomance tuningMichel Schildmeijer
 
Deployment Strategies
Deployment StrategiesDeployment Strategies
Deployment StrategiesMongoDB
 

Similar to Understanding salt modular sub-systems and customization (20)

Salt at school
Salt at schoolSalt at school
Salt at school
 
Wielding a cortana
Wielding a cortanaWielding a cortana
Wielding a cortana
 
Deployment of WebObjects applications on CentOS Linux
Deployment of WebObjects applications on CentOS LinuxDeployment of WebObjects applications on CentOS Linux
Deployment of WebObjects applications on CentOS Linux
 
Running CentOS on the Facebook fleet
Running CentOS on the Facebook fleetRunning CentOS on the Facebook fleet
Running CentOS on the Facebook fleet
 
Owning computers without shell access 2
Owning computers without shell access 2Owning computers without shell access 2
Owning computers without shell access 2
 
Puppet Camp NYC 2014: Build a Modern Infrastructure in 45 min!
Puppet Camp NYC 2014: Build a Modern Infrastructure in 45 min!Puppet Camp NYC 2014: Build a Modern Infrastructure in 45 min!
Puppet Camp NYC 2014: Build a Modern Infrastructure in 45 min!
 
Deploying to Ubuntu on Linode
Deploying to Ubuntu on LinodeDeploying to Ubuntu on Linode
Deploying to Ubuntu on Linode
 
Debugging webOS applications
Debugging webOS applicationsDebugging webOS applications
Debugging webOS applications
 
SecurityFest-22-Fitzl-beyond.pdf
SecurityFest-22-Fitzl-beyond.pdfSecurityFest-22-Fitzl-beyond.pdf
SecurityFest-22-Fitzl-beyond.pdf
 
How we use Twisted in Launchpad
How we use Twisted in LaunchpadHow we use Twisted in Launchpad
How we use Twisted in Launchpad
 
Deployment Strategy
Deployment StrategyDeployment Strategy
Deployment Strategy
 
Owning computers without shell access dark
Owning computers without shell access darkOwning computers without shell access dark
Owning computers without shell access dark
 
Deploying PHP on PaaS: Why and How?
Deploying PHP on PaaS: Why and How?Deploying PHP on PaaS: Why and How?
Deploying PHP on PaaS: Why and How?
 
Deployment Strategies (Mongo Austin)
Deployment Strategies (Mongo Austin)Deployment Strategies (Mongo Austin)
Deployment Strategies (Mongo Austin)
 
unit 2 confinement techniques.pdf
unit 2 confinement techniques.pdfunit 2 confinement techniques.pdf
unit 2 confinement techniques.pdf
 
Building with Virtual Development Environments
Building with Virtual Development EnvironmentsBuilding with Virtual Development Environments
Building with Virtual Development Environments
 
[HES2013] Virtually secure, analysis to remote root 0day on an industry leadi...
[HES2013] Virtually secure, analysis to remote root 0day on an industry leadi...[HES2013] Virtually secure, analysis to remote root 0day on an industry leadi...
[HES2013] Virtually secure, analysis to remote root 0day on an industry leadi...
 
Oracle WebLogic Diagnostics & Perfomance tuning
Oracle WebLogic Diagnostics & Perfomance tuningOracle WebLogic Diagnostics & Perfomance tuning
Oracle WebLogic Diagnostics & Perfomance tuning
 
Ranger BSides-FINAL
Ranger BSides-FINALRanger BSides-FINAL
Ranger BSides-FINAL
 
Deployment Strategies
Deployment StrategiesDeployment Strategies
Deployment Strategies
 

Recently uploaded

%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisamasabamasaba
 
The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is insideshinachiaurasa2
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...panagenda
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park masabamasaba
 
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesVictorSzoltysek
 
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfonteinmasabamasaba
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplatePresentation.STUDIO
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providermohitmore19
 
Exploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdfExploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdfproinshot.com
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...harshavardhanraghave
 
10 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 202410 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 2024Mind IT Systems
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrainmasabamasaba
 
%in Durban+277-882-255-28 abortion pills for sale in Durban
%in Durban+277-882-255-28 abortion pills for sale in Durban%in Durban+277-882-255-28 abortion pills for sale in Durban
%in Durban+277-882-255-28 abortion pills for sale in Durbanmasabamasaba
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...masabamasaba
 
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park masabamasaba
 
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...masabamasaba
 
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...Nitya salvi
 
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...SelfMade bd
 
SHRMPro HRMS Software Solutions Presentation
SHRMPro HRMS Software Solutions PresentationSHRMPro HRMS Software Solutions Presentation
SHRMPro HRMS Software Solutions PresentationShrmpro
 

Recently uploaded (20)

%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is inside
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
 
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
 
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation Template
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
Exploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdfExploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdf
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
 
10 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 202410 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 2024
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
%in Durban+277-882-255-28 abortion pills for sale in Durban
%in Durban+277-882-255-28 abortion pills for sale in Durban%in Durban+277-882-255-28 abortion pills for sale in Durban
%in Durban+277-882-255-28 abortion pills for sale in Durban
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
 
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
 
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
 
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...
 
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
 
SHRMPro HRMS Software Solutions Presentation
SHRMPro HRMS Software Solutions PresentationSHRMPro HRMS Software Solutions Presentation
SHRMPro HRMS Software Solutions Presentation
 

Understanding salt modular sub-systems and customization

  • 2. About Me (Jason Denning) • DevOps Engineer • SaltStack user for ~ 3 years • SaltStack Certified Engineer #2 • AWS Certified Architect • OSS Advocate (first Linux install ~ 1998) • Pythonista • jasondenning on GitHub / @jason_denning on Twitter
  • 3. ● Provide analytics and marketing/segmentation tools for mobile app developers ● Hosted backend APIs available world- wide ● Lots of traffic ● Big fans of SaltStack ● upsight.com
  • 4. Frustratingly Flexible • Salt is extremely flexible and extensible • Highly modular / easy to customize • Can be difficult (at first) to know where your custom code should go • Occasionally confusing nomenclature • Pillar • Grains • Mine • Reactor • ...
  • 5. But once you know your way around.. ...Salt’s pretty awesome • Easy to customize • Scalable • Secure • Doesn’t suffer from the Pareto Principal (80% rule)
  • 6. This Talk You’ll (hopefully) understand: • When to use different functionality • How all the pieces fit together • How to get started customizing Salt • Where to go next
  • 7. Salt’s not Configuration Management • Salt is a remote execution framework • Run arbitrary code on remote hosts • Tools to make this easy and flexible • Configuration Management is just a common use-case • Originally intended to be a tool for managing cloud-based infrastructure
  • 8. Remote Execution 101 Basic remote execution: $ ssh jason@myhost "ls /home/jason" it_worked.txt Multiple hosts? $ for h in myhost1 myhost2 myhost3; > do ssh jason@myhost "ls /home/jason"; > done
  • 9. Remote Execution 101 Ok, but what if: • I want to run it on 100 hosts? • My login credentials are different on some hosts? • I actually want to do something with the output? • I want to do this many times?
  • 10. Remote Execution 102 How about a script? #!/bin/bash # Make sure your SSH config (~/.ssh/config) is setup! command=$1 host_list=$2 for h in host_list; do ssh "$h" "$command" done # FIXME: Add output handling # FIXME: Add error handling # FIXME: Add logging # TODO: FIND A BETTER WAY TO DO THIS!!!!
  • 11. Looks like we need: A script that can handle: ● Executing arbitrary commands ● ...on one or more remote hosts ● …with a sane way to get the output (STDOUT? Write a file? Text output? JSON? YAML??) ● …and graceful error handling ● …and logging ● …and authentication ● …and everything else I haven't thought of yet!
  • 12. And then we realize.. ● We only want to run a command if the host is in a particular state... ● the command is different for some hosts because they have a different OS... ● we need to configure host X before we configure host Y... ● we want to generate a file from a template, using data from an external database ● we need to keep that external data secret
  • 13. You want me to maintain a 5,000 line BASH Script?
  • 14. I’m convinced - let’s use a framework This is why Salt has so many modular subsystems: • Each type of component scratches a particular itch (there’s some overlap) • ⇒ Modular • Someone is inevitably going to want something slightly different • ⇒ Extensible • We’re almost always going to want things like error handling • ⇒ One framework instead of several mini-frameworks
  • 15. Salt Basics • A host can be a “master”, “minion”, “masterless”, or any combination • a master can instruct minions to run code (via ‘salt’ cmd) • a minion can trigger actions on itself using code/configuration stored on its master (via ‘salt-call’ cmd) • a minion can run in isolation, called “masterless” (via ‘salt-call’) • a single machine can run both master and minion daemons The point: Some subsystems run on the master, some on the minion
  • 16. The Event Sub-System Salt transfers commands and other data (including files)between hosts via the Event Sub-System. • Publish/Subscribe message queue (based on ZeroMQ) • Master can publish messages on minion queues, and vice-versa • Code execution on the minion is triggered via Event messages • Output is sent back to the master from the minion in the same fashion • Messages are encrypted, and authenticated with Salt’s Public Key Infrastructure (PKI) • Reactor: Watches the message queue on the master, and triggers code execution when it sees specific events
  • 17. How Salt Works (simplified) $ salt minion1 cmd.run Salt Master <do stuff> minion1 Master Message Bus (zmq / RAET) Message (Event) Message (Event) Minion Message Bus (zmq / RAET) Message (Event) Message (Event) <Encrypted>
  • 18. Code Execution Sub-Systems • Execution Modules (a.k.a. “modules”): Code that executes on the minion • Runner Modules: Code that executes on the master • State Modules: Code that executes on the minion, depending on the current state of the host (typically utilize execution modules)
  • 19. Code Execution: CLI • ‘salt’ command: (from master) instruct minion(s) to invoke an execution module, which executes code on the minion • ‘salt-call’ command: (from minion) invoke an execution module, which executes code on the minion • ‘salt-run’ command: (from master) invoke a runner module, which executes code on the master
  • 20. Data Sub-Systems • Pillar: Data which is passed to a particular minion via the master • Pillar Modules: Code that runs on the master which generates Pillar data • Grains: Data which is set directly on the minion • Grains Modules: Code that runs on the minion which generates Grains data • Mine: Data collected from minion(s) which is stored on the master, and made available to all other minions
  • 21. Major Subsystems: Output Handling • Output Modules: Format output from the CLI • e.g. text (human-readable), YAML, JSON • Returner Modules: Send output to external data-stores • e.g. syslog, MySQL, etcd • Note: Minions always return output to the master on the Event bus, regardless of whether Returner modules are used or not
  • 22. SLS Files • Human-readable files, with the .sls extension • Processed by the Renderer subsystem to create data structures that are understood by other sub-systems • Most users interact with Salt via SLS files • Renderer Modules: Convert SLS files into usable data structures (execute on both master and minion) • Composable (e.g. Jinja + YAML) • Can access Pillar and Grains data
  • 23. Targeting Minions • A salt-master can target minions based on the minions’ ids, Grains, or Pillar data • States and Pillar data are assigned to via the Master Tops sub- system (typically, this is just a file, called top.sls) • Salt-SSH targets hosts (which aren’t running the minion daemon) via the Roster sub-system
  • 24. Other Modular Sub-Systems • Auth : Enable external authentication systems • Fileserver: File storage backends used by the master • Wheel: Used to manage the master’s configuration • Net-API: Access the master via the web New in 2015.2: • Engine: Long-running code on either master or minion • Beacons: Code running on minions, used to translate external events to the Event bus
  • 25. More Stuff!?!? • Salt Cloud: Manage cloud (IaaS) infrastructure • Salt SSH: Apply salt states on hosts without a minion daemon, via SSH • Salt Virt: Manage virtual hosts and hypervisors • Proxy-Minions: Manage “dumb” hardware, such as network hardware
  • 26. That’s a lot of sub-systems!
  • 27. Let’s Get Customizin’ • First, make sure that you actually need to write code • http://salt.readthedocs.org/en/latest/ref/modules/all/index.html • http://salt.readthedocs.org/en/latest/ref/states/all/index.html • … etc. • https://github.com/saltstack/salt-contrib • Look at existing module code: • https://github.com/saltstack/salt/tree/2015.2/salt/modules • https://github.com/saltstack/salt/tree/2015.2/salt/states • … etc.
  • 28. Custom Execution Modules # _modules/hello_world.py ‘’’ This comment will print if you run $ salt-call sys.doc hello ‘’’ __virtualname__ = ‘hello’ def world(): ‘’’ Prints “Hello World!” - this will print if you run $salt-call sys.doc hello.world’’’ print(“Hello World!”)
  • 29. Custom Execution Modules • Need to determine if the module can run on this minion? • write a function called “__virtual__()” • if __virtual__() returns False, the module will not be available • Useful if your code has external dependencies • Need a “private” function? • Prefix the function name with an underscore • i.e. _this_is_invisible_to_the_user() • Any function that doesn’t begin with an underscore will be callable
  • 30. Custom Execution Modules - Imports # A useful pattern if you need to import an external library try: import foomodule HAS_FOO = True except ImportError: HAS_FOO = False def __virtual__(): ‘’’Only load the execution module if we could import foomodule’’’ if HAS_FOO: return True else: return False
  • 31. Accessing Other Modules • When Salt loads your module, it will create a couple of magic dicts, just like in SLS files • __salt__ : use to call other execution modules • e.g. __salt__[‘cmd.run’](“ls /”) • __grains__ : use to access grains • e.g. minion_id = __grains__[‘id’]
  • 32. Custom State Modules • Much like execution modules • Need to return a dict with this format: { ‘result’: True, ‘comment’: “Info about the state execution”, ‘changes’: { ‘old’: ‘the state before function was applied’, ‘new’: ‘state after the function was applied’ } } • ‘result’ should be True if the state is correct, False if there was an error, or None if this was a test run
  • 33. Custom State Modules - Tips • State functions must accept a ‘name’ argument, at minimum • Enable test mode! ($ salt-call state.sls mystate.foo test=True) • Write a function called “mod_init(low)” which accepts the Low State Data Structure to do one-time setup and initialization • If you want to enable the ‘watch’ requisite, write a function called “mod_watch()” - see the service state for a good example
  • 34. Example State From the documentation: http://docs.saltstack.com/en/latest/ref/states/writing.html#example-state-module
  • 35. Recap • Salt makes it easy to run custom code on your infrastructure, with lots of icing • Lots of modular sub-systems, but they’re useful! • Write custom code once, run many times • No 5,000 line BASH scripts!
  • 36. Now we can run whatever code we want!