FreeKB - Getting Started with variables
Ansible - Getting Started with variables

There are 20+ ways to create variables in Ansible, such as on the command line, in a playbook, or from a file, just to name a few.

Common ways to create variables

Following are common ways that variables are created. This is in the order of precedence, top down, where the option higher in the list takes precedence.



Ansible uses Jinja2 templating system for variables. In Jinja2, a variable has this structure.

{{ ... }}


For example, let's say a variable named "foo" contains a value of "bar". This is how you would use the "foo" variable to return "bar".

{{ foo }}


Here is an example of using a Jinja2 variable in the debug module. Notice the message is wrapped in double quotes.

- debug:
    msg: "The foo variable contains a value of {{ foo }}"


Add a Comment

We will never share your name or email with anyone. Enter your email if you would like to be notified when we respond to your comment.

Please enter 0312a in the box below so that we can be sure you are a human.