Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Mastering Ansible

You're reading from   Mastering Ansible Design, develop, and solve real world automation and orchestration needs by unlocking the automation capabilities of Ansible

Arrow left icon
Product type Paperback
Published in Nov 2015
Publisher Packt
ISBN-13 9781784395483
Length 236 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Toc

Control structures

In Jinja2, a control structure refers to things in a template that control the flow of the engine parsing the template. These structures include, but are not limited to, conditionals, loops, and macros. Within Jinja2 (assuming the defaults are in use), a control structure will appear inside blocks of {% … %}. These opening and closing blocks alert the Jinja2 parser that a control statement is provided instead of a normal string or variable name.

Conditionals

A conditional within a template creates a decision path. The engine will consider the conditional and choose from two or more potential blocks of code. There is always a minimum of two: a path if the conditional is met (evaluated as true), and an implied else path of an empty block.

The statement for conditionals is the if statement. This statement works much like it does in Python. An if statement can be combined with one or more optional elif with an optional final else, and unlike Python, requires an explicit...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime