Book Image

Learning SaltStack - Second Edition

By : Colton Myers
Book Image

Learning SaltStack - Second Edition

By: Colton Myers

Overview of this book

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. We?ll 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.
Table of Contents (17 chapters)
Learning SaltStack Second Edition
Credits
About the Author
About the Reviewer
www.PacktPub.com
Preface
Index

Jinja2


Jinja2 is a templating language for Python. Templating provides a mechanism by which you can create content for files using code blocks to generate content dynamically. Jinja2 is modeled after the Django template language, so if you've ever developed in Django, the syntax should feel familiar. Even if you haven't, the syntax bears a resemblance to Pythons syntax, so it's not very hard to pick up.

There are two main types of Jinja2 syntaxes used in Salt. The first is variable, which uses double curly braces (the spaces around foo are for readability and are not required), and which is shown in the following code:

{{ foo }}
{{ foo.bar }}
{{ foo['bar'] }}
{{ get_data() }}

For these examples, the contents of the referenced variable or the results of the function call are placed in the document at the location of the Jinja2 block.

Jinja2 also has access to basic control statements. Control statement blocks use a curly brace and percentage sign, which is depicted in the following code:

{% %...