Mastering SaltStack
By Hall Joseph
()
About this ebook
Take charge of SaltStack to automate and configure enterprise-grade environments
About This Book- Automate tasks effectively, so that your infrastructure can run itself
- Take advantage of cloud-based services that can expand the capabilities of your own data centers
- Tackle real-world problems that appear in everyday situations
SaltStack is known as a popular configuration management system, but that barely scratches the surface. It is, in fact, a powerful automation suite, which is designed not only to help you manage your servers, but to help them manage themselves. SaltStack is used worldwide by organizations ranging from just a few servers, to tens of thousands of nodes across data centers in multiple continents. This award-winning software is fast becoming the standard for systems management in the cloud world.
This book will take you through the advanced features of SaltStack, bringing forward capabilities that will help you excel in the management of your servers.
You will be taken through the the mind of the modern systems engineer, and discover how they use Salt to manage their infrastructures, and why those design decisions are so important. The inner workings of Salt will be explored, so that as you advance your knowledge of Salt, you will be able to swim with the current, rather than against it.
Various subsystems of Salt are explained in detail, including Salt SSH, Salt Cloud, and external pillars, filesystems, and job caches.
You will be taken through an in-depth discussion of how to effectively scale Salt to manage thousands of machines, and how to troubleshoot issues when things don't go exactly the way you expect them to.
You will also be taken through an overview of RAET, Salt's new transport protocol, and given an insight into how this technology improves Salt, and the possibilities that it brings with it.
What You Will Learn- Learn how the pros are managing their infrastructures, and what techniques they use to keep everything running smoothly with Salt
- Understand what makes Salt tick, and how that affects the way you use it
- Take a look at familiar features in a new light, so that you have a better handle on how to approach tasks
- Use Salt SSH to manage servers that don't fit Salt's traditional use cases
- Besides automating your configuration, you will be able to automate your servers, and make them behave more intelligently
- Make better use of cloud-based services, including compute clouds such as EC2, Azure and Openstack
- Learn about the new RAET protocol, and how it changes the way automation works
This book is ideal for professionals who have been managing groups of servers, and want to learn how to add functionality and expand their tool set. This book will also explain some of the more advanced features of Salt, and explore how to use them to bring additional power to the fundamentals that the professionals have already been using.
Style and approachThis book speaks informally, sometimes almost conversationally, to the user. Topics are covered in detail, using examples that should be comfortable to most users.
Read more from Hall Joseph
Selections from Early Middle English 1130-1250: Part II: Notes Rating: 0 out of 5 stars0 ratingsExtending SaltStack Rating: 0 out of 5 stars0 ratingsMastering SaltStack - Second Edition Rating: 0 out of 5 stars0 ratingsIdeal Commonwealths Rating: 0 out of 5 stars0 ratingsSelections from early Middle English, 1130-1250 Part I: Texts Rating: 0 out of 5 stars0 ratings
Related to Mastering SaltStack
Related ebooks
Learning SaltStack Rating: 4 out of 5 stars4/5Mastering SaltStack - Second Edition Rating: 0 out of 5 stars0 ratingsLearning SaltStack - Second Edition Rating: 0 out of 5 stars0 ratingsTroubleshooting Ubuntu Server Rating: 0 out of 5 stars0 ratingsWebSphere Application Server 7.0 Administration Guide Rating: 0 out of 5 stars0 ratingsIPsec VPN A Complete Guide - 2019 Edition Rating: 0 out of 5 stars0 ratingsSCCM A Complete Guide - 2019 Edition Rating: 0 out of 5 stars0 ratingsEVPN for VXLAN The Ultimate Step-By-Step Guide Rating: 0 out of 5 stars0 ratingsPractical LPIC-3 300: Prepare for the Highest Level Professional Linux Certification Rating: 0 out of 5 stars0 ratingsStorage Area Network Essentials: A Complete Guide to Understanding and Implementing SANs Rating: 0 out of 5 stars0 ratingsSystem Center 2012 R2 Virtual Machine Manager Cookbook Rating: 0 out of 5 stars0 ratingsMCSA Windows Server 2012 R2 Complete Study Guide: Exams 70-410, 70-411, 70-412, and 70-417 Rating: 0 out of 5 stars0 ratingsApplication Development for IBM WebSphere Process Server 7 and Enterprise Service Bus 7 Rating: 0 out of 5 stars0 ratingsWindows Server 2008 For Dummies Rating: 0 out of 5 stars0 ratingsWildFly Cookbook Rating: 0 out of 5 stars0 ratingsCloud Computing with the Windows Azure Platform Rating: 4 out of 5 stars4/5Storage area network The Ultimate Step-By-Step Guide Rating: 0 out of 5 stars0 ratingsMastering Puppet Rating: 0 out of 5 stars0 ratingsPro Exchange 2019 and 2016 Administration: For Exchange On-Premises and Office 365 Rating: 0 out of 5 stars0 ratingsMCSA: Windows 10 Complete Study Guide: Exam 70-698 and Exam 70-697 Rating: 0 out of 5 stars0 ratingsNetstat A Complete Guide - 2021 Edition Rating: 0 out of 5 stars0 ratingsPKI Management A Complete Guide - 2019 Edition Rating: 0 out of 5 stars0 ratingsMicrosoft 365 Administration Cookbook: Enhance your Microsoft 365 productivity to manage and optimize its apps and services Rating: 0 out of 5 stars0 ratingsVMware vCenter Cookbook Rating: 0 out of 5 stars0 ratingsWindows 11 for Enterprise Administrators: Unleash the power of Windows 11 with effective techniques and strategies Rating: 0 out of 5 stars0 ratingsPKI Architecture The Ultimate Step-By-Step Guide Rating: 0 out of 5 stars0 ratingsThe Very Simple Basics Of Setting Up A Website Rating: 0 out of 5 stars0 ratingsWindows Server 2016 Hyper-V Cookbook - Second Edition Rating: 0 out of 5 stars0 ratingsPKI Deployments A Complete Guide - 2020 Edition Rating: 0 out of 5 stars0 ratings
Computers For You
Elon Musk Rating: 4 out of 5 stars4/5The Invisible Rainbow: A History of Electricity and Life Rating: 5 out of 5 stars5/5The Innovators: How a Group of Hackers, Geniuses, and Geeks Created the Digital Revolution Rating: 4 out of 5 stars4/5Uncanny Valley: A Memoir Rating: 4 out of 5 stars4/5The ChatGPT Millionaire Handbook: Make Money Online With the Power of AI Technology Rating: 4 out of 5 stars4/5Procreate for Beginners: Introduction to Procreate for Drawing and Illustrating on the iPad Rating: 5 out of 5 stars5/5Slenderman: Online Obsession, Mental Illness, and the Violent Crime of Two Midwestern Girls Rating: 4 out of 5 stars4/5Everybody Lies: Big Data, New Data, and What the Internet Can Tell Us About Who We Really Are Rating: 4 out of 5 stars4/5CompTIA IT Fundamentals (ITF+) Study Guide: Exam FC0-U61 Rating: 0 out of 5 stars0 ratingsMastering ChatGPT: 21 Prompts Templates for Effortless Writing Rating: 4 out of 5 stars4/5CompTIA Security+ Get Certified Get Ahead: SY0-701 Study Guide Rating: 5 out of 5 stars5/5Deep Search: How to Explore the Internet More Effectively Rating: 5 out of 5 stars5/5The Hacker Crackdown: Law and Disorder on the Electronic Frontier Rating: 4 out of 5 stars4/5Standard Deviations: Flawed Assumptions, Tortured Data, and Other Ways to Lie with Statistics Rating: 4 out of 5 stars4/5Tor and the Dark Art of Anonymity Rating: 5 out of 5 stars5/5Excel 101: A Beginner's & Intermediate's Guide for Mastering the Quintessence of Microsoft Excel (2010-2019 & 365) in no time! Rating: 0 out of 5 stars0 ratingsSQL QuickStart Guide: The Simplified Beginner's Guide to Managing, Analyzing, and Manipulating Data With SQL Rating: 4 out of 5 stars4/5Alan Turing: The Enigma: The Book That Inspired the Film The Imitation Game - Updated Edition Rating: 4 out of 5 stars4/5The Professional Voiceover Handbook: Voiceover training, #1 Rating: 5 out of 5 stars5/5People Skills for Analytical Thinkers Rating: 5 out of 5 stars5/5Creating Online Courses with ChatGPT | A Step-by-Step Guide with Prompt Templates Rating: 4 out of 5 stars4/5Learning the Chess Openings Rating: 5 out of 5 stars5/5Ultimate Guide to Mastering Command Blocks!: Minecraft Keys to Unlocking Secret Commands Rating: 5 out of 5 stars5/5Grokking Algorithms: An illustrated guide for programmers and other curious people Rating: 4 out of 5 stars4/5The Data Warehouse Toolkit: The Definitive Guide to Dimensional Modeling Rating: 0 out of 5 stars0 ratings
Reviews for Mastering SaltStack
0 ratings0 reviews
Book preview
Mastering SaltStack - Hall Joseph
Table of Contents
Mastering SaltStack
Credits
Foreword
About the Author
About the Reviewers
www.PacktPub.com
Support files, eBooks, discount offers, and more
Why subscribe?
Free access for Packt account holders
Preface
What this book covers
What you need for this book
Who this book is for
Conventions
Reader feedback
Customer support
Errata
Piracy
Questions
1. Reviewing a Few Essentials
Executing commands remotely
Master and Minions
Targeting Minions
Glob
Perl Compatible Regular Expression (PCRE)
List
Subnet
Grain
Grain PCRE
Pillar
Compound
Nodegroup
Using module functions
test.ping
test.echo
test.sleep
test.version
pkg.install
pkg.remove
file.replace
Other file functions
Various user and group functions
sys.doc
SLS file trees
SLS files
Tying things together with top files
Organizing the SLS directories
Using States for configuration management
Using include blocks
Ordering with requisites
require
watch
onchanges
onfail
use
prereq
Inverting requisites
Extending SLS files
The basics of Grains, Pillars, and templates
Using Grains for Minion-specific data
Centralizing variables with Pillars
Managing files dynamically with templates
A quick Jinja primer
Summary
2. Diving into Salt Internals
Understanding the Salt configuration
Following the configuration tree
Looking inside /etc/salt/
Managing Salt keys
Exploring the SLS directories
Examining the Salt cache
The Master job cache
The Master-side Minion cache
The external file server cache
The Minion-side proc/ directory
External modules
The Renderer
Rendering SLS files
Render pipes
Serving templated files
Understanding the Loader
Dynamic modules
Execution modules
Cloud modules
Plunging into the State compiler
Imperative versus declarative
Requisites
High and Low States
High States
Low States
Enforcing statefulness
name
result
changes
comment
Summary
3. Exploring Salt SSH
Grappling with SSH
Remote shells
Using rosters
The flat roster
host
port
user
passwd
sudo
priv
timeout
thin_dir
Other built-in rosters
scan
cache
cloud
ansible
Building dynamic rosters
Using Salt SSH
Using a Saltfile
Salt versus Salt SSH
Architecture
Performance
Understanding the salt-thin agent
Building the thin package
Including extra modules
Deploying the thin package
Executing the thin package
The Salt SSH shim
Preparing for Salt States
Running Salt
Salt's running data
Using the raw SSH mode
Caching SSH connections
Summary
4. Managing Tasks Asynchronously
Looking at the event system
Reviewing the basics
The structure of event data
Watching event data
Installing the event listener
Using the event listener
Firing custom data
Namespacing events
Namespacing guidelines
Some common events
salt/auth
salt/key
salt/minion/
salt/job/
salt/job/
salt/presence/present
salt/presence/change
Common cloud events
salt/cloud/
salt/cloud/
salt/cloud/
salt/cloud/
salt/cloud/
salt/cloud/
salt/cloud/
salt/cloud/
Salt API events
salt/netapi/
Building Reactors
Configuring Reactors
Writing Reactors
Calling execution modules
Calling runner modules
Calling wheel modules
Writing more complex Reactors
Sending out alerts
Using webhooks
Reactors calling Reactors
Using the queue system
Learning how queues work
Adding to the queue
Listing queues
Listing items in a queue
Processing queue items
Deleting items from a queue
Using queues with the Reactor
Spreading out State runs
Dividing tasks among Minions
Summary
5. Taking Salt Cloud to the Next Level
Examining the Salt Cloud configuration
Global configurations
The provider and profile configuration
Providers
Profiles
Extending configuration blocks
Building custom deploy scripts
Understanding the Salt Bootstrap script
Installing from prebuilt packages
Installing from Git
Looking back at legacy deploy scripts
Writing your own deploy scripts
Passing arguments to scripts
Using file maps
Taking a look at cloud maps
Working with autoscale Reactors
The cloud cache
Using cloud cache events
Setting up a schedule
Catching cloud cache events
Summary
6. Using Salt with REST
Looking at Salt's HTTP library
Why a Salt-specific library?
Using the http.query function
GET versus POST
Decoding return data
Using the http.query state
Using http.query with Reactors
Understanding Salt API
What is Salt API?
Setting up Salt API
CherryPy
Tornado
WSGI
Creating SSL certificates
Configuring authentication
The external authentication module
Taking your first steps with Salt API
Issuing one-off commands
Working with webhooks
Security considerations
More complex authentication
Summary
7. Understanding the RAET Protocol
Comparing RAET and ZeroMQ
Starting with HTTP
SSH, the old favorite
Using ZeroMQ
ZeroMQ and security
The need for RAET
Flow-based programming
The pieces of the puzzle
Black boxes
Shared storage
Concurrent scheduling
Driving with RAET
Configuring RAET
The RAET architecture
The basics
The RAET scheduler
Estates and yards
Summary
8. Strategies for Scaling
All about syndication
Different folks, different strokes
No need for micro-managing
Configuring syndication
High availability with multiple Masters
Built-in high availability configuration
Old-school high availability
The round robin DNS
IP-based load balancing
Synchronizing files
Base configuration files
Synchronizing the nonexternal files
Using rsync
Using the event Reactor
Incorporating external data sources
The external job cache
Using Returners on the Minions
Using the Master job cache
External filesystems
GitFS
base
root
mountpoint
user and password
insecure_auth
pubkey, privkey, and passphrase
Other source control backends
SVNFS
root and mountpoint
trunk
branches
tags
HGFS
S3FS
One environment per bucket
Multiple environments per bucket
AzureFS
External Pillars
cmd_yaml/cmd_json
git
redis
mysql
Using the Master API
The Salt keys
Configuration
The file and Pillar roots
Using the Wheel Reactor
Testing load in the infrastructure
Using the Minion Swarm
Swarm internals
Summary
9. Monitoring with Salt
Monitoring basics
Establishing a baseline
Reading the system vitals in Salt
status.loadavg
status.cpustats
status.meminfo
status.vmstats
disk.usage, status.diskusage
status.w
status.all_status, status.custom
Monitoring with Returners
Deciding on a Returner
Using monitoring states
Defining a monitoring state
Monitoring with web calls
Working with beacons
Monitoring file changes
Beacon intervals
Setting up alerts
Alerting in State files
Alerting from beacons
Watching file changes
Monitoring bad logins
Summary
10. Exploring Best Practices
Future-proofing your infrastructure
Setting up your directories
Standard directory locations
Shallow versus deep
Subdividing further
The SLS efficiency
Includes and extends
Using includes
Using extends
Using templates to simplify SLS files
Working with loops
Decisions, decisions
Using the built-in States
Naming conventions
Generic names
Explicit names
Templates and variables
Nested variables
Referring to variables in templates
Summary
11. Troubleshooting Problems
What the…?
Addressing the problem source
Where is the trouble?
The Master to Minion communication
The network and CPU congestion
Checking the Minion load
Querying the Salt job data
Using debug and trace modes
info
warn
error
debug/trace
Running services in debug mode
Using salt-call locally
Working with YAML
YAML basics
dict
list
YAML idiosyncrasies
Spacing
Numbers
Booleans
List items
Troubleshooting YAML
Asking the community for help
The salt-users mailing list
Asking questions
The Salt issue tracker
Researching before posting
Formatting your issues
Requesting features
#salt on IRC
Final community thoughts
Summary
Index
Mastering SaltStack
Mastering SaltStack
Copyright © 2015 Packt Publishing
All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews.
Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author nor Packt Publishing, and its dealers and distributors will be held liable for any damages caused or alleged to be caused directly or indirectly by this book.
Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information.
First published: August 2015
Production reference: 1130815
Published by Packt Publishing Ltd.
Livery Place
35 Livery Street
Birmingham B3 2PB, UK.
ISBN 978-1-78528-216-4
www.packtpub.com
Credits
Author
Joseph Hall
Reviewers
Pedro Algarvio
Darrel Clute
JiWei Liu
Hoàng Đình Quân
Peng Yao
Commissioning Editor
Kartikey Pandey
Acquisition Editor
Vivek Anantharaman
Content Development Editor
Merwyn Dsouza
Technical Editor
Siddhesh Patil
Copy Editors
Relin Hedly
Sonia Mathur
Project Coordinator
Neha Bhatnagar
Proofreader
Safis Editing
Indexer
Monica Mehta
Graphics
Disha Haria
Production Coordinator
Nilesh R. Mohite
Cover Work
Nilesh R. Mohite
Foreword
This is the Salt book I have been wanting to see for a long time. As the creator of Salt, I feel that many people don't know about the advanced and powerful capabilities of the Salt platform. Diving into the parts of Salt less trodden is where the truly amazing value of Salt comes into play. The more powerful aspects of Salt, such as how to use the Reactor for dynamic intelligent management, how to use salt-ssh to manage a wide variety of situations, and how to take Salt to the next level, are revealed in this book in an easy-to-understand way. I hope that this book will be a great help in bringing the great power of Salt to more people.
Joseph Hall is likely the best person to write this book. He is not only a close friend, but has also been involved with the Salt project from the very beginning, including the early design of the Salt States system. Joseph is the second person to write code for Salt (apart from me). He was the first engineer hired by SaltStack.
Thomas S. Hatch
Founder and CTO, SaltStack
About the Author
Joseph Hall has touched just about every area of the modern technology world from his beginnings as a support technician to being a web programmer, QA engineer, systems administrator, Linux instructor, and cloud engineer. He is currently a senior cloud and integrations engineer at SaltStack. Joseph enjoys working with some of the best minds in the business with his coworkers and SaltStack's partners. He is also a classically trained chef. Joseph's supreme pleasure lies in working with what he calls computational gastronomy.
I would like to thank my wife, Nat, for her support when I stayed up every night to write this book. I would also like to thank Tom Hatch for writing Salt and having the guts to turn it into the best company that I've ever worked for. My sincere thanks go out to Colton Meyers for hooking me up with Packt Publishing. I would also like to thank the Salt community for being awesome and helping make Salt what it is today.
About the Reviewers
Pedro Algarvio was a Sound Technician until May 2015. He likes to keep himself busy. Therefore, Pedro set out to make computers work for him. In his endeavor to deepen his knowledge of computers, he started with shell scripting and then moved on to learn Perl, and finally settled with Python. Pedro was involved with several open source projects. However, he credits Salt for giving him the opportunity to learn the most. He joined SaltStack in May 2015 and dedicated his time to improve the Salt software.
I would like to thank my wife for her continuous friendship, love, and support throughout. She even supported me when I took the risk of quitting my job to to pursue a skill, in which I had no experience. I would also like to thank my twins for allowing me some spare time to review Joseph's book. Further, I want to thank the Salt community for teaching me new things everyday. Last but not least, I would like to thank God.
I love learning new things. SaltStack gave the opportunity to learn more about Salt, which made me grow as a Python coder and enthusiast. I would like to thank SaltStack for their continuous belief and encouragement to the point of inviting me to join the team.
Darrel Clute is an IT infrastructure architect. Throughout his career, he has predominately focused on network engineering. Darrel has also spent an equal amount of time focusing on systems engineering, primarily with Unix-based systems. Apart from his job, he is also an advocate of the open source software. This is used in enterprise as well as for individuals. Darrel will never advocate the use of open source purely for the sake of it.
Outside his core competencies, he also has extensive experience with proprietary and open source virtualization platforms. His knowledge and experience with IaaS solutions—such as OpenStack—is constantly increasing as well. Additionally, with his systems engineering experience, Darrel has been exposed to and has supported various web and enterprise applications. His most recent exposure has been to PaaS solutions. This has led him to advocate that a public or private cloud offering is not complete without coupling IaaS and PaaS solutions designed and deployed in lockstep.
Beyond his core infrastructure, Darrel has recently been developing programing skills to augment his daily activities. Throughout his career, he has utilized various languages and utilities to automate infrastructure. Some of Darrel's programming has been with the use of Bash, net-snmp, sed, awk, and holistically Python.
JiWei Liu graduated in 2011. He is employed as a cloud computing and operation and maintenance engineer at Gamewave Group Limited (PRC), China's largest web game provider. It is also the leader of the Chinese web game industry and the professional provider of interactive entertainment services.
I would like to thank my sweetheart for her help and support in the process of writing this book.
Hoàng Đình Quân is a junior system administrator and network infrastructure engineer. He has extensive experience in designing, deploying, hardening, and maintaining Linux systems and the network infrastructure for small-and medium-sized companies.
Peng Yao is an operations engineer with more than 8 years of experience in infrastructure automation, data visualization, and cloud computing. He is the founder and coordinator of the China SaltStack user group.
www.PacktPub.com
Support files, eBooks, discount offers, and more
For support files and downloads related to your book, please visit www.PacktPub.com.
Did you know that Packt offers eBook versions of every book published, with PDF and ePub files available? You can upgrade to the eBook version at www.PacktPub.com and as a print book customer, you are entitled to a discount on the eBook copy. Get in touch with us at
At www.PacktPub.com, you can also read a collection of free technical articles, sign up for a range of free newsletters and receive exclusive discounts and offers on Packt books and eBooks.
https://www2.packtpub.com/books/subscription/packtlib
Do you need instant solutions to your IT questions? PacktLib is Packt's online digital book library. Here, you can search, access, and read Packt's entire library of books.
Why subscribe?
Fully searchable across every book published by Packt
Copy and paste, print, and bookmark content
On demand and accessible via a web browser
Free access for Packt account holders
If you have an account with Packt at www.PacktPub.com, you can use this to access PacktLib today and view 9 entirely free books. Simply use your login credentials for immediate access.
Preface
I'm very excited to have been given the chance to put this book together. From an idea in the brain of Tom Hatch to an award-winning open source project to the flagship product of an award-winning open source company, I've been given the rare opportunity to watch Salt grow. Salt has become an incredibly powerful framework, which I wish I had access to years ago.
Everyday, I learn something new about Salt. This book is a collection of a number of these things, which is aimed at the advanced user. Don't see it as the last word on any of the topics it covers. Instead, see it as a guide to using this tool to its fullest potential on your journey.
As you read through this book, I hope that the ideas and examples in it inspire you to update and innovate your infrastructure.
What this book covers
Chapter 1, Reviewing a Few Essentials, talks about how to review a few fundamental concepts to get into the right frame of mind. While many of the concepts should be familiar to the experienced user, you are likely to find plenty of new information as well.
Chapter 2, Diving into Salt Internals, jumps into the deeper workings behind Salt. It discusses the internal configuration, the loader system, renderers, and the state compiler.
Chapter 3, Exploring Salt SSH, explores how Salt SSH is a powerful tool. It's been getting a lot of love from the core developers lately. This is possibly the most complete discussion of Salt SSH.
Chapter 4, Managing Tasks Asynchronously, discusses how one of the most important concepts behind Salt is asynchronicity. This chapter lays down the fundamentals that will be referenced throughout the rest of the book.
Chapter 5, Taking Salt Cloud to the Next Level, goes deeper, exposing parts of Salt Cloud, which turn casual users into experts. No matter how much you've used Salt Cloud, there's a good chance you've only scratched the surface.
Chapter 6, Using Salt with REST, talks about how it's almost impossible to work with technology these days without depending on REST services. It uses Salt to tie these services to your infrastructure with ease.
Chapter 7, Understanding the RAET Protocol, teaches you the concepts behind RAET and how they impact upon you. RAET is still new, but it's already found its way into large organizations.
Chapter 8, Strategies for Scaling, talks about how to never assume that your infrastructure will stay small. It makes you think about how to scale your infrastructure properly before it's too late.
Chapter 9, Monitoring with Salt, discovers how Salt is a powerful monitoring tool if you know how to use it. It tells you how to integrate it with existing tools or use Salt alone.
Chapter 10, Exploring Best Practices, discusses the good and bad ways to use any tool. It teaches you the good ways to use Salt.
Chapter 11, Troubleshooting Problems, tells you where to look and how to find help when things go wrong.
What you need for this book
To follow the examples in this book, you should be running at least version 2015.5 of Salt. Only one machine is strictly necessary because both the salt-master and the salt-minion service can be run together, but Linux is currently required to run the salt-master service.
The examples in this book are targeted at Ubuntu Linux, except where stated otherwise.
Who this book is for
This book is ideal for professionals who have been managing groups of servers and want to learn how to add functionality and expand their toolset. This book explains some of the more advanced features of Salt. It explores how to use them to bring additional power to the fundamentals that the professionals have already been using.
Conventions
In this book, you will find a number of text styles that distinguish between different kinds of information. Here are some examples of these styles and an explanation of their meaning.
Code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles are shown as follows: This function does little more than the test.ping command.
A block of code is set as follows:
nodegroups:
webdev: 'I@role:web,G@cluster:dev'
webqa: 'I@role:web,G@cluster:qa'
webprod: 'I@role:web,G@cluster:prod'
Any command-line input or output is written as follows:
# salt -S 192.168.0.0/24 test.ping
New terms and important words are shown in bold. Words that you see on the screen, for example, in menus or dialog boxes, appear in the text like this: Click the Join This Group link and you will be subscribed
.
Note
Warnings or important notes appear in a box like this.
Tip
Tips and tricks appear like this.
Reader feedback
Feedback from our readers is always welcome. Let us know what you think about this book—what you liked or disliked. Reader feedback is important for us as it helps us develop titles that you will really get the most out of.
To send us general feedback, simply e-mail <[email protected]>, and mention the book's title in the subject of your message.
If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide at www.packtpub.com/authors.
Customer support
Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.
Errata
Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you find a mistake in one of our books—maybe a mistake in the text or the code—we would be grateful if you could report this to us. By doing so, you can save other readers from frustration and help us improve subsequent versions of this book. If you find any errata, please report them by visiting http://www.packtpub.com/submit-errata, selecting your book, clicking on the Errata Submission Form link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata will be uploaded to our website or added to any list of existing errata under the Errata section of that title.
To view the previously submitted errata, go to https://www.packtpub.com/books/content/support and enter the name of the book in the search field. The required information will appear under the Errata section.
Piracy
Piracy of copyrighted material on the Internet is an ongoing problem across all media. At Packt, we take the protection of our copyright and licenses very seriously. If you come across any illegal copies of our works in any form on the Internet, please provide us with the location address or website name immediately so that we can pursue a remedy.
Please contact us at <[email protected]> with a link to the suspected pirated material.
We appreciate your help in protecting our authors and our ability to bring you valuable content.
Questions
If you have a problem with any aspect of this book, you can contact us at <[email protected]>, and we will do our best to address the problem.
Chapter 1. Reviewing a Few Essentials
Salt is a very powerful automation framework. Before we delve into the more advanced topics that this book covers, it may be wise to go back and review a few essentials. In this chapter, we will cover the following topics:
Using remote execution
Basic SLS file tree structure
Using States for configuration management
Basics of Grains, Pillars, and templates
This book assumes that you already have root access on a device with a common distribution of Linux installed. The machine used in the examples in this book is running Ubuntu 14.04, unless stated otherwise. Most examples should run on other major distributions, such as recent versions of Fedora, RHEL 5/6/7, or Arch Linux.
Executing commands remotely
The underlying architecture of Salt is based on the idea of executing commands remotely. This is not a new concept; all networking is designed around some aspect of remote execution. This could be as simple as asking a remote Web server to display a static Web page, or as complex as using a shell session to interactively issue commands against a remote server.
Under the hood, Salt is an example of one of the more complex types of remote execution. But whereas most Internet users are used to interacting with only one server at a time (so far as they are aware), Salt is designed to allow users to explicitly target and issue commands to multiple machines directly.
Master and Minions
Salt is based around the idea of a Master, which controls one or more Minions. Commands are normally issued from the Master to a target group of Minions, which then execute the tasks specified in the commands and then return any resulting data back to the Master.
Targeting Minions
The first facet of the salt command is targeting. A target must be specified with each execution, which matches one or more Minions. By default, the type of target is a glob, which is the style of pattern matching used by many command shells. Other types of targeting are also available, by adding a flag. For instance, to target a group of machines inside a particular subnet, the -S option is used:
# salt -S 192.168.0.0/24 test.ping
The following are most of the available target