Ansible Variable

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 the ‘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 }}"



Relevant Blogs:

Ansible Modules 

Ansible tower 

Ansible Variable 

Statefulset in kubernetes

Recent Comments

No comments

Leave a Comment