Designing for reusability
Ansible provides variables for turning Ansible playbooks into reusable templates. You can substitute variables in the right places using Jinja2 markup, which we've already used in the last playbook. Let's now look at Ansible variables, their types, and how to use them.
Ansible variables
Ansible variables, like any other variables, are used to manage differences between managed nodes. You can use a similar playbook for multiple servers, but sometimes there are some differences in configuration. Ansible variables help you template your playbooks so that you can reuse them for a variety of similar systems. There are multiple places where you can define your variables:
- Within the Ansible playbook within the
vars
section - In your inventory
- In reusable files or roles
- Passing variables through the command line
- Registering variables by assigning the return values of a task
Ansible variable names can include letters, numbers...