Ansible Variables  

create your own web page for free
Mobirise

Ansible Variables

Variable in playbooks are very similar to using variables in any programming language. It helps you to use and assign a value to a variable and use that anywhere in the playbook. One can put conditions around the value of the variables and accordingly use them in the playbook.
These values are essential to deciding the code flow. Ansible variables help to determine how the tasks execute on different systems based on the values assigned to these variables.
Ansible variable names should be letters, numbers, underscores and they should always start with a letter.

Basic Ansible Variable example
In the playbook, we can give a variable in ‘variable_name: variable_value‘ format. And we can use the variable_name inside double braces anywhere in the playbook. In the following task, I am declaring a variable hello with value world and is referenced in one of the tasks. The task will output the value world.

- hosts: all
vars:
hello: world
tasks:
- name: Ansible Basic Variable Example
debug:
msg: "{{ hello }}"
Ansible Group_vars

Ansible uses a combination of a hosts file and a group_vars directory to pull variables per host group and run Ansible plays/tasks against hosts. group_vars/all is used to set variables that will be used for every host that Ansible is ran against.

Blocks
The playbook in totality is broken into blocks. The smallest piece of steps to execute is written in block. Writing the specific instruction in blocks helps to segregate functionality and handle it with exception handling if needed. 

CONTACT FORM

Address

172-173, 5th floor
Chandrasekharan Avenue
Old Mahabalipuram Road
(Above Axis Bank-PTC Bus Stop)
Thoraipakkam
Chennai 600097




Contacts
Email:   admin@zippyops.com
Phone: +91 7010585768
              +91 8903067727