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. Following are common ways that variables can be created. This list is in the order of precedence, where the option higher in the list takes precedence over options lower in the list.


Let's say you have a variable defined twice. For example, let's say the foo variable is defined in the vars plugin and contains a value of Hello.

- hosts: all
    foo: "Hello"


Let's also say that the --extra-vars command line option is being used to set the foo variable to contain a value of World.

ansible-playbook example.yml --extra-vars "foo=World"


In this scenario, the foo variable would contain a value of World, because the --extra-vars command line option takes precedence over the vars plugin.



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 39ed2 in the box below so that we can be sure you are a human.


Web design by yours truely - me, myself, and I   |   |