Comparing values

Comparisons are used in many places with Ansible. Task conditionals are comparisons. Jinja2 control structures often use comparisons. Some filters use comparisons as well. To master Ansible's usage of Jinja2, it is important to understand which 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:

Expression

Definition

==

Compares two objects for equality

!=

Compares two objects for inequality

>

True if the left-hand side is greater than the right-hand side

<

True if the left-hand side is less than the right- hand side

>=

True if the left-hand side is greater than or ...

Get Mastering Ansible now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.