Configuration: group variables
Group variables are variables that are applied to groups of servers. They can be used in templates and in
playbooks to customize behavior and to provide easily-changed settings and parameters. They are stored in
a directory calledgroup_varsin the same location as your inventory.
Here is lamp_haproxy’sgroup_vars/allfile. As you might expect, these variables are applied to all of the machines in your inventory:
This is a YAML file, and you can create lists and dictionaries for more complex variable structures.
In this case, we are just setting two variables, one for the port for the web server, and one for the
NTP server that our machines should use for time synchronization.
Here’s another group variables file. This isgroup_vars/dbserverswhich applies to the hosts in thedbserversgroup:
If you look in the example, there are group variables for thewebserversgroup and thelbserversgroup, similarly.
These variables are used in a variety of places. You can use them in playbooks, like this, inroles/db/tasks/main.yml:
You can also use these variables in templates, like this, inroles/common/templates/ntp.conf.j2: