# Ansible Variables

In 
Published 2022-12-03

This tutorial explains to you how to use variables in Ansible. This tutorial has an example as well.

Ansible variable are used in playbooks and 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.

In order to use variables it is better to create a file or more files if needed in which we keep the variable name and the variable value. This must be a YAML file.

The variable could be defined inside the playbook as well.

In my example I use the following inventory and variable file (variables.yml):

My playbook has the following content:

The variable is marked with . In my case my variable is state1. This notation is named JinJa2 (JinJa2 templating).

Now you can run the Ansible playbook, and you can see how the playbook is running using the variable.