Extending SaltStack
eBook - ePub

Extending SaltStack

Joseph Hall

Share book
  1. 240 pages
  2. English
  3. ePUB (mobile friendly)
  4. Available on iOS & Android
eBook - ePub

Extending SaltStack

Joseph Hall

Book details
Book preview
Table of contents
Citations

About This Book

Extend the power of your infrastructure and applications with Salt modules

About This Book

  • Get the most up-to-date practical resource on writing new Salt modules and extending Salt
  • Learn through use cases and encounter both commonly-used modules as well as advanced ones
  • Effectively troubleshoot problems and hiccups encountered while building and putting modules to work

Who This Book Is For

This book is for both new and existing Salt developers who are looking to build and write new Salt modules. Some prior Python development experience is expected.

What You Will Learn

  • Understand the working of Salt's Loader system
  • Write several of the most common types of Salt modules
  • Interact between different kinds of modules and build new ones
  • Submit open source modules upstream to the Salt project
  • Make Salt interact with third-party services and applications

In Detail

Salt already ships with a very powerful set of tools, but that doesn't mean that they all suit your needs perfectly. By adding your own modules and enhancing existing ones, you can bring the functionality that you need to increase your productivity. Extending SaltStack follows a tutorial-based approach to explain different types of modules, from fundamentals to complete and full-functioning modules.

Starting with the Loader system that drives Salt, this book will guide you through the most common types of modules. First you will learn how to write execution modules. Then you will extend the configuration using the grain, pillar, and SDB modules. Next up will be state modules and then the renderers that can be used with them. This will be followed with returner and output modules, which increase your options to manage return data. After that, there will be modules for external file servers, clouds, beacons, and finally external authentication and wheel modules to manage the master.

With this guide in hand, you will be prepared to create, troubleshoot, and manage the most common types of Salt modules and take your infrastructure to new heights!

Style and approach

This book follows a step-by-step tutorial-based approach explaining the different types of modules, from fundamentals to complete and full-functioning modules.

Frequently asked questions

How do I cancel my subscription?
Simply head over to the account section in settings and click on “Cancel Subscription” - it’s as simple as that. After you cancel, your membership will stay active for the remainder of the time you’ve paid for. Learn more here.
Can/how do I download books?
At the moment all of our mobile-responsive ePub books are available to download via the app. Most of our PDFs are also available to download and we're working on making the final remaining ones downloadable now. Learn more here.
What is the difference between the pricing plans?
Both plans give you full access to the library and all of Perlego’s features. The only differences are the price and subscription period: With the annual plan you’ll save around 30% compared to 12 months on the monthly plan.
What is Perlego?
We are an online textbook subscription service, where you can get access to an entire online library for less than the price of a single book per month. With over 1 million books across 1000+ topics, we’ve got you covered! Learn more here.
Do you support text-to-speech?
Look out for the read-aloud symbol on your next book to see if you can listen to it. The read-aloud tool reads text aloud for you, highlighting the text as it is being read. You can pause it, speed it up and slow it down. Learn more here.
Is Extending SaltStack an online PDF/ePUB?
Yes, you can access Extending SaltStack by Joseph Hall in PDF and/or ePUB format, as well as other popular books in Computer Science & System Administration. We have over one million books available in our catalogue for you to explore.

Information

Year
2016
ISBN
9781785888618
Edition
1

Extending SaltStack


Table of Contents

Extending SaltStack
Credits
Foreword
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
Downloading the color images of this book
Errata
Piracy
Questions
1. Starting with the Basics
Using plugins
Loading modules
Standard modules
Virtual modules
Lazy loading modules
Extending the loader system
Loading modules with Python
Detecting grains
Using other detection methods
Summary
2. Writing Execution Modules
Writing Salt modules
Hidden objects
The __virtual__() function
Formatting your code
Virtual modules
Using the salt.utils library
Cross-calling with the __salt__ dictionary
Getting configuration parameters
Handling imports
Reusing code
Logging messages
Using the __func_alias__ dictionary
Validating data
Formatting strings
The final module
Troubleshooting execution modules
Using salt-call
<function> is not available
Summary
3. Extending Salt Configuration
Setting grains dynamically
Setting some basic grains
(Not) cross-calling execution modules
The final grains module
Creating external pillars
Configuring external pillars
Adding an external pillar
Another external pillar
Troubleshooting grains and pillars
Dynamic grains not showing up
External pillars not showing up
Writing SDB modules
Getting SDB data
Setting SDB data
Using a descriptive docstring
Using more complex configuration
The final SDB module
Using SDB modules
Troubleshooting SDB modules
SDB data not showing up
Summary
4. Wrapping States Around Execution Modules
Forming a state module
Determining state
The __virtual__() function
Setting up defaults
Checking for truth
Checking for test mode
Attempting to configure the resource
Notifying about False
Example: checking an HTTP service
Checking credentials
The first stateful function
Another stateful function
Troubleshooting state modules
Step 1: test for truth
Step 2: test mode
Step 3: applying changes
Testing opposites
Summary
5. Rendering Data
Understanding file formats
Serializing data
Working with templates
Using render pipes
Building a serializing renderer
The basic structure
Building a templating renderer
Templating with Tenjin
Using a templating renderer
Troubleshooting renderers
Summary
6. Handling Return Data
Returning data to external destinations
Returning data to the master
Listening to event data
When returners listen to Minions
Your first returner
Using job caches
The final module
Troubleshooting returners
Testing with salt-call
Testing with the Master running
Testing with runners
Writing outputter modules
Pickling our output
Troubleshooting outputters
Summary
7. Scripting with Runners
Using Salt's local client
Scripting with the local client
Using different targets
Combining jobs to add more logic
The final module
Troubleshooting runners
Working with the salt-master service
Timeout issues
Summary
8. Adding External File Servers
How Salt uses files
Mimicking a filesystem
Looking at each function
Setting up our module
envs()
file_list() and dir_list()
find_file()
serve_file()
update()
file_hash()
The final module
Troubleshooting file servers
Start small
Test on a Minion
Summary
9. Connecting to the Cloud
Understanding cloud components
Looking at the puzzle pieces
Connection mechanism
Listing resources
Creating virtual machines
Managing other resources
Libcloud versus SDK versus direct REST API
Writing a generic cloud module
Checking for required configuration
Using http.query()
A common REST API
GET
POST
PATCH
DELETE
Setting up a _query() function
Getting profile details
Listing images
Listing sizes
Listing locations
Listing nodes
Querying standard node data
Querying full node data
Creating a VM
Destroying VMs
Using actions and functions
Using actions
Using functions
The final cloud module
Troubleshooting cloud modules
Write avail_sizes() or avail_images() first
Use shortcuts
Summary
10. Monitoring with Beacons
Watching for data
Keeping an eye on things
Validating configuration
The beacon() function
Watching for beacons
The final beacon module
Troubleshooting beacons
Summary
11. Extending the Master
Using external authentication
Authenticating credentials
Troubleshooting external authentication
Setting auth parameters
Testing with the salt command
Testing with Salt API
Managing the Master with the wheel modules
Wrapping a wheel around runners
The final wheel module
Troubleshooting wheel modules
Summary
A. Connecting Different Modules
Separating Master and Minion functionality
Working with dunders
Using the event bus
Firing events
B. Contributing Code Upstream
How the community works
Asking questions and reporting issues
Using the mailing list
Using IRC
Using the issue tracker
Using GitHub markdown
Understanding the Salt Style Guide
Using Pylint
Creating pull requests on GitHub
Using other branches
Understanding test errors in pull requests
Index

Extending SaltStack

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: March 2016
Production reference: 1160316
Published by Packt Publishing Ltd.
Livery Place
35 Livery Street
Birmingham B3 2PB, UK.
ISBN 978-1-78588-861-8
www.packtpub.com

Credits

Author
Joseph Hall
Reviewers
C. R. Oldham
Mike Place
Commissioning Editor
Kunal Parikh
Acquisition Editor
Reshma Raman
Content Development Editor
Merwyn D'souza
Technical Editor
Mohit Hassija
Copy Editors
Dipti Mankame
Jonathan Todd
Project Coordinator
Nikhil Nair
Proofreader
Safis Editing
Indexer
Priya Sane
Graphics
Kirk D'Penha
Production Coordinator
Shantanu N. Zagade
Cover Work
Shantanu N. Zagade

Foreword

Regardless of your current experience with Salt, you will find this book a necessary addition to unlock the full potential and capabilities of S...

Table of contents