Operators In Ansible

Operators In Ansible

Operators in Ansible

Hello Everyone

Welcome to CloudAffaire and this is Debjeet.

In the last blog post, we have discussed variables in Ansible.

https://cloudaffaire.com/variables-in-ansible/

In this blog post, we will discuss operators in Ansible.

What is operator?

Programming languages typically support a set of operators: constructs which behave generally like functions, but which differ syntactically or semantically from usual functions. Common simple examples include arithmetic (addition with +), comparison (with >), and logical operations (such as AND or &&). More involved examples include assignment (usually = or :=), field access in a record or object (usually .), and the scope resolution operator (often ::). Languages usually define a set of built-in operators, and in some cases allow users to add new meanings to existing operators or even define completely new operators.

As already referenced in the variables section, Ansible uses Jinja2 templating to enable dynamic expressions and access to variables. Ansible supports all the operators provided by Jinja2 like math, comparison, logical and other special Jinja2 operators.

Next, we are going to explain each operator type with a demo.

Math Operator: Math operators are used to perform mathematical operations like addition, multiplication etc.

Comparison Operators: Comparison operators are used to compare between two values.

Logical Operators: Logical operators are used to perform logical operations like AND, OR etc.

Special Operators: Jinja2 provides a set of special operators like filter to perform special operations.

Hope you have enjoyed this article. In the next blog post, we will discuss conditions in Ansible.

To get more details on Ansible, please refer below Ansible documentation.

https://docs.ansible.com/

 

Leave a Reply

Close Menu