O'Reilly logo

Learning SaltStack - Second Edition by Colton Myers

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required