Comparing values
Comparisons are used in many places with Ansible. Task conditionals are comparisons. Jinja2 control structures, such as if
/elif
/else
blocks, for
loops, and macros, often use comparisons; some filters use comparisons as well. To master Ansible's usage of Jinja2, it is important to understand what comparisons are available.
Comparisons
Like most languages, Jinja2 comes equipped with the standard set of comparison expressions you would expect, which will render a Boolean true
or false
.
The expressions in Jinja2 are as follows:
If you have written comparison operations in almost any other programming language (usually in the form of an if
statement), these should all seem very familiar. Jinja2 maintains this functionality in templates, allowing for the same powerful comparison operations you would expect in conditional logic from any good programming language.
Logic
Sometimes, performing a single...