Variables and Variable Files
Variables are a critical part of any scripting or development language, and Ansible is no different. Variables act as named placeholders for data elements, important information, numerical values, and more. Ansible provides a vars section and a vars_files section, which are optionally included in a playbook. Variables defined here are playbook-centric and can be used within the playbook. These sections of the playbook allow us to define variables in two unique ways. Let's look at an example to better understand how variables are defined:
---
- hosts: all
vars:
myvar: helloworld
vars_files:
- /vars/my_vars.ymlAs we can see from the example, we can be rather creative when defining variables that Ansible can use in its playbook. Variables can be specified via the vars section, the vars_files section, or even via the command line through the ExtraVars parameter. Let's take a look at the key/value implementation of variables as well as a vars_file implementation...