Chapter 5. Controlling Execution Flow – Conditionals
Control structures refer to anything and everything that have an effect on a program's execution flow. Control structures are mainly of the following two types:
- Conditional
- Iterative
At times, we need to execute code conditionally based on a value of a variable, type of platform, or even a result of some other command. There are times when we also need to iterate multiple objects, such as list hashes or multilevel variables.
Most programming languages and tools use powerful but machine-friendly constructs, such as if else
, for
, unless
, do while
, and so on. However, Ansible stays true to its design tenet of being a human-friendly automation language and manages to achieve the same with the omnipotent when
and with_*
constructs, which are closer to the English language. Let's begin to explore how it does so.
In this chapter, we are going to cover the following topics:
- Using conditional controls with the
when
statements...