Learning SaltStack - Second Edition
By Colton Myers
()
About this ebook
Build, manage, and secure your infrastructure by utilizing the power of SaltStack
About This Book- First book in the market to incorporate all the latest features of SaltStack.
- Leverage the power of SaltStack for building, managing and securing your infrastructure.
- Effectively use commands and control the state of your infrastructure in a jiffy.
This book is aimed at System Administrators who are looking forward to manage their infrastructure using SaltStack with no prior knowledge about it.
What You Will Learn- Install Salt on your servers
- Run commands on all or some of your minions instantly from a central managing server
- Write custom Salt modules to handle your infrastructure's unique needs
- Define the state of your infrastructure and use Salt to enforce that state.
- Create platform-agnostic state definitions for greater flexibility and power
- Manage virtual servers on public or private clouds using Salt Cloud
- Use the event system in Salt to create a reactive and self-healing infrastructure
SaltStack is one of the best infrastructure management platforms available. It provides powerful tools for defining and enforcing the state of your infrastructure in a clear, concise way. With this book learn how to use these tools for your own infrastructure by understanding the core pieces of Salt.
In this book we will take you from the initial installation of Salt, through running their first commands, and then talk about extending Salt for individual use cases. From there you will explore the state system inside of Salt, learning to define the desired state of our infrastructure in such a way that Salt can enforce that state with a single command. Finally, you will learn about some of the additional tools that salt provides, including salt-cloud, the reactor, and the event system. Well finish by exploring how to get involved with salt and what's new in the salt community.
Finally, by the end of the book, you'll be able to build a reliable, scalable, secure, high-performance infrastructure and fully utilize the power of cloud computing.
Style and approachThis will be a comprehensive guide on SaltStack along with installation and setting up of Salt on couple of platforms. Then enlightening the readers about remote execution system and configuration management system and ending with concepts of security and best practices.
Read more from Colton Myers
Learning SaltStack Rating: 4 out of 5 stars4/5Learning SaltStack - Second Edition Rating: 0 out of 5 stars0 ratings
Related to Learning SaltStack - Second Edition
Related ebooks
Extending SaltStack Rating: 0 out of 5 stars0 ratingsSalt Open: Automating Your Enterprise and Your Network Rating: 0 out of 5 stars0 ratingsThe DevOps 2.0 Toolkit Rating: 0 out of 5 stars0 ratingsThe Complete Metasploit Guide: Explore effective penetration testing techniques with Metasploit Rating: 0 out of 5 stars0 ratingsOpenStack Essentials - Second Edition Rating: 0 out of 5 stars0 ratingsHands-On Microservices with C#: Designing a real-world, enterprise-grade microservice ecosystem with the efficiency of C# 7 Rating: 0 out of 5 stars0 ratingsSpring: Microservices with Spring Boot: Build and deploy microservices with Spring Boot Rating: 0 out of 5 stars0 ratingsLearning Ansible 2 - Second Edition Rating: 5 out of 5 stars5/5Learning Splunk Web Framework Rating: 0 out of 5 stars0 ratingsOpenfire Administration Rating: 0 out of 5 stars0 ratingsRobot Operating System Cookbook: Over 70 recipes to help you master advanced ROS concepts Rating: 0 out of 5 stars0 ratingsLinux Shell Scripting Bootcamp Rating: 0 out of 5 stars0 ratingsEffective Python Penetration Testing Rating: 0 out of 5 stars0 ratingsMicroservices Development Cookbook: Design and build independently deployable modular services Rating: 0 out of 5 stars0 ratingsPython Microservices Development: Build, test, deploy, and scale microservices in Python Rating: 4 out of 5 stars4/5Developing Microservices with Node.js Rating: 0 out of 5 stars0 ratingsLearn Qt 5: Build modern, responsive cross-platform desktop applications with Qt, C++, and QML Rating: 0 out of 5 stars0 ratingsDocker High Performance Rating: 0 out of 5 stars0 ratingsLearning Nagios - Third Edition Rating: 0 out of 5 stars0 ratingsStyleCop Code Analysis How-to: Learn how to analyze and maintain code for your projects using StyleCop Rating: 0 out of 5 stars0 ratingsMastering Play Framework for Scala Rating: 0 out of 5 stars0 ratingsPractical OneOps: Implement DevOps with ease Rating: 0 out of 5 stars0 ratingsInstant Play Framework Starter: Build your web applications from the ground up with the Play Framework for Java and Scala Rating: 0 out of 5 stars0 ratingsBuilding Slack Bots Rating: 0 out of 5 stars0 ratingsGetting Started with Hazelcast - Second Edition Rating: 0 out of 5 stars0 ratingsPostman Cookbook Rating: 0 out of 5 stars0 ratingsSpring Security Essentials Rating: 0 out of 5 stars0 ratings
Networking For You
The Compete Ccna 200-301 Study Guide: Network Engineering Edition Rating: 5 out of 5 stars5/5AWS Certified Cloud Practitioner Study Guide: CLF-C01 Exam Rating: 5 out of 5 stars5/5Programming Arduino: Getting Started with Sketches Rating: 4 out of 5 stars4/5Networking All-in-One For Dummies Rating: 5 out of 5 stars5/5Concise and Simple Guide to IP Subnets Rating: 5 out of 5 stars5/5A Beginner's Guide to Ham Radio Rating: 0 out of 5 stars0 ratingsLinux Bible Rating: 0 out of 5 stars0 ratingsCybersecurity: The Beginner's Guide: A comprehensive guide to getting started in cybersecurity Rating: 5 out of 5 stars5/5The Windows Command Line Beginner's Guide: Second Edition Rating: 4 out of 5 stars4/5CCNA Certification Study Guide, Volume 2: Exam 200-301 Rating: 0 out of 5 stars0 ratingsEmergency Preparedness and Off-Grid Communication Rating: 3 out of 5 stars3/5Group Policy: Fundamentals, Security, and the Managed Desktop Rating: 0 out of 5 stars0 ratingsUnlock Any Roku Device: Watch Shows, TV, & Download Apps Rating: 0 out of 5 stars0 ratingsWindows Command Line Administration Instant Reference Rating: 0 out of 5 stars0 ratingsQuantum Computing For Dummies Rating: 0 out of 5 stars0 ratingsNetworking For Dummies Rating: 5 out of 5 stars5/5CompTIA Network+ Certification Guide (Exam N10-008): Unleash your full potential as a Network Administrator (English Edition) Rating: 0 out of 5 stars0 ratingsCompTIA Network+ Practice Tests: Exam N10-008 Rating: 0 out of 5 stars0 ratingsHacking Android Rating: 5 out of 5 stars5/5Raspberry Pi Electronics Projects for the Evil Genius Rating: 3 out of 5 stars3/5Microsoft Azure For Dummies Rating: 0 out of 5 stars0 ratingsNetworking Fundamentals: Develop the networking skills required to pass the Microsoft MTA Networking Fundamentals Exam 98-366 Rating: 0 out of 5 stars0 ratingsMicrosoft Certified Azure Fundamentals Study Guide: Exam AZ-900 Rating: 0 out of 5 stars0 ratingsA Practical Guide Wireshark Forensics Rating: 5 out of 5 stars5/5PowerShell Troubleshooting Guide Rating: 0 out of 5 stars0 ratingsPractical Ethical Hacking from Scratch Rating: 5 out of 5 stars5/5Nmap Essentials Rating: 4 out of 5 stars4/5Computer Networking: An introductory guide for complete beginners: Computer Networking, #1 Rating: 5 out of 5 stars5/5
Reviews for Learning SaltStack - Second Edition
0 ratings0 reviews
Book preview
Learning SaltStack - Second Edition - Colton Myers
Table of Contents
Learning SaltStack Second Edition
Credits
About the Author
About the Reviewer
www.PacktPub.com
eBooks, discount offers, and more
Why subscribe?
Preface
What this book covers
What you need for this book
Who this book is for
Conventions
Reader feedback
Customer support
Downloading the example code
Errata
Piracy
Questions
1. Diving In – Our First Salt Commands
Introducing Salt
Installing Salt
Installation with system packages (Ubuntu)
Installation with system packages (CentOS 6)
Installation with system packages (Windows)
Installing with Salt Bootstrap
Configuring Salt
Firewall configuration
Salt minion configuration
Starting the Salt master and Salt minion
Accepting the minion key on the master
A game of ping pong
Masterless Salt
Summary
2. Controlling Your Minions with Remote Execution
The structure of a remote execution command
Command-line options
Targeting strings
Glob matching
Perl-compatible regular expression matching
List matching
Grain and pillar matching
Using grains
Using pillars
Compound matching
Remote execution modules and functions
Adding users
Installing packages
Managing services
Monitoring minion states
Running arbitrary commands
Summary
3. Execution Modules – Write Your Own Solution
Exploring the source
Cross-calling execution modules
Grains and the __virtual__ function
The__opts__ and __pillar__ functions
Reformatting return data
An advanced example
Summary
4. Defining the State of Your Infrastructure
Our first state
The pieces of a state declaration
Expanding to encompass multiple pieces of state
Dependencies using requisites
The require requisite
The watch requisite
Other requisites
The _in requisites
Summary
5. Expanding Our States with Jinja2 and Pillar
Adding a new minion
Jinja2
apache2 or httpd?
Defining secure minion-specific data in pillar
Using pillar data in states
Summary
6. The Highstate and Environments
The highstate
Environments
Environments in pillar
Expanding our base environment
Storing our states in Git with GitFS
Summary
7. Using Salt Cloud to Manage Virtual Minions
Setting up Salt Cloud
Setting up Linode
Creating an API key
Creating a cloud provider configuration
Creating cloud VM profiles
Creating and destroying machines
Managing groups of VMs with map files
Creating new masters with the map files
Summary
8. The Reactor and the Event System
The Salt event system
Listening for events
Event structure
Firing events from Salt
Firing events from custom code
Reacting to events
Summary
9. Security Best Practices in Salt
Securing Salt configuration
Master configuration
open_mode and auto_accept
file_recv
Peer publishing
Minion configuration
master_finger
Key management
Preseeding the minion keys
Preseeding the master key
Verifying with key fingerprints
Master fingerprint
Minion fingerprints
Firewall and network configuration
Summary
10. How Can I Get Involved?
Contributing code using GitHub
Creating an account on GitHub
The project
Getting the code
Contributing a fix
Committing our changes
Pushing the changes and creating a pull request
Other ways to get involved
Salt-users mailing list
#salt on freenode IRC
#saltstack on the hangops Slack
Summary
Index
Learning SaltStack Second Edition
Learning SaltStack Second Edition
Copyright © 2016 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: January 2015
Second edition: June 2016
Production reference: 1270616
Published by Packt Publishing Ltd.
Livery Place
35 Livery Street
Birmingham B3 2PB, UK.
ISBN 978-1-78588-190-9
www.packtpub.com
Credits
Author
Colton Myers
Reviewer
Joseph Hall
Commissioning Editor
Pratik Shah
Acquisition Editor
Divya Poojari
Content Development Editor
Rashmi Suvarna
Technical Editors
Manali Gonsalves
Novina Kewalramani
Pramod Kumavat
Copy Editor
Dipti Mankame
Project Coordinator
Judie Jose
Proofreader
Safis Editing
Indexer
Hemangini Bari
Graphics
Kirk D'Penha
Production Coordinator
Shantanu N. Zagade
Cover Work
Shantanu N. Zagade
About the Author
Colton Myers is a software engineer living in Salt Lake City, Utah. Since graduating with a BS in Computer Science from the University of Utah, he has worked professionally, writing software in Python. He loves working on open source software and has made multiple appearances as a speaker at the US PyCon conference.
Colton is a SaltStack Certified Trainer and has worked on the Salt open source software for years. He was previously a core engineer at SaltStack. At the time this book was published, he was a Python developer and systems engineer at Adobe.
Find him on Twitter and Github at @basepi.
I would like to thank my friends and family for the support they've given me as I've written this book. I'd also like to thank Tom Hatch for creating such kick-ass software, and growing a fantastic company and community. Finally, I'd like to thank the SaltStack community; without them, SaltStack would be nothing.
About the Reviewer
Joseph Hall is a Senior Cloud Engineer at SaltStack. His contributions inside Salt include a number of execution modules, cloud modules, and the creation of both SDB and SPM. He is also the author of Mastering SaltStack and Extending SaltStack, both by Packt Publishing.
www.PacktPub.com
eBooks, discount offers, and more
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.
eBooks, discount offers, and morehttps://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
Preface
SaltStack (or Salt, for short) is an open source project that was started by Thomas Hatch in 2011. It was originally intended to be a lightning-fast remote execution system. Later, the various pieces that make up the Salt that we know today were added on top of this flexible layer. Salt is now one of the most popular open source projects in the world and one of the most popular infrastructure management platforms.
The project is managed by SaltStack, Inc., a company dedicated to preserving the open source nature of the software. SaltStack, Inc. provides service, long-term support, and custom code in their enterprise product, and supports the open source Salt project with a team of dedicated engineers.
Why do you care? What can Salt do for you?
Salt is the easiest, most powerful way to manage your servers. Whether you have a few, hundreds, or even tens of thousands of servers, you can use Salt to manage them from a single central point. You can use it to flexibly target any subset of your servers to run commands or accomplish tasks. You can use the state system to define the state of your infrastructure in a data-driven way and then enforce that state in seconds, with a single command. You can even create a reactive, self-healing infrastructure using the event system. Salt is written in Python and designed to be easy to extend for your own specific use-cases or purposes.
We're going to learn how to do all this and more in these pages. By the end of this book, you will have the knowledge you need to begin making the management of your infrastructure easier with Salt.
Let's get to it!
What this book covers
Chapter 1, Diving In – Our First Salt Commands, will discuss how to install Salt and execute basic commands.
Chapter 2, Controlling Your Minions with Remote Execution, will show how to use Salt to accomplish tasks on your minions through remote execution.
Chapter 3, Execution Modules – Write Your Own Solution, will discuss how to write your own custom remote execution modules to extend Salt for your own purposes.
Chapter 4, Defining the State of Your Infrastructure, will discuss how to use Salt States to define and enforce the state of your infrastructure.
Chapter 5, Expanding Our States with Jinja2 and Pillar, will discuss how to make your states more flexible and powerful by using Jinja2 and Pillar data.
Chapter 6, The Highstate and Environments, will show how to structure your states into environments and enforce the state of your entire infrastructure using a single command.
Chapter 7, Using Salt Cloud to Manage Virtual Minions, will show how to manage your cloud virtual machines using salt-cloud to create and manage VMs.
Chapter 8, The Reactor and the Event System, will show how to make your infrastructure automatically react to changes by using the reactor and event system built into Salt.
Chapter 9, Security Best Practices in Salt, will show how to secure your SaltStack infrastructure from attackers.
Chapter 10, How Can I Get Involved?, will show how to go beyond this book and learn more about Salt, as well as how to get involved in the SaltStack community.
What you need for this book
You will need access to a Linux machine to run the examples in this book. The preferred operating system is Ubuntu 14.04, but any major distribution of Linux is acceptable. If you use an operating system other than Ubuntu 14.04, your output may differ from the example output in the book.
Who this book is for
The biggest target audience for this book is system administrators. However, anyone who works with servers, whether application/web developers, system administrators, or hobbyists, will be able to use to this book to learn how to manage their servers/infrastructure easily and consistently.
No prior Salt knowledge is assumed. However, even Salt veterans will find new knowledge and best practices to apply in their own infrastructures. This book is for anyone who wants to better manage their infrastructure with Salt.
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: Now, you must open the file /etc/apt/sources.list and add the following line.
A block of code is set as follows:
test_state
file.managed:
- name: /tmp/test.txt
- source: salt://test.txt
- user: root
- group: root
- mode: 644
When we wish to draw your attention to a particular part of a code block, the relevant lines or items are set in bold:
test_state
file.managed:
- name: /tmp/test.txt
- source: salt://test.txt
- user: root
- group: root
- mode: 644
Any command-line input or output is written as follows:
# cp /usr/src/asterisk-addons/configs/cdr_mysql.conf.sample /etc/asterisk/cdr_mysql.conf
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: Continue the installation process by clicking Next and agreeing to the license agreement.
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