Tips on where to set variables
You should choose where to define a variable based on the kind of control you might want over values.
Set variables in inventory that deal with geography or behavior. Since groups are frequently the entity that maps roles to hosts, you can often set variables on the group instead of defining them on a role. Remember that child groups override parent groups, and host variables override group variables. SeeDefining variables in inventoryfor details on setting host and group variables.
Set common defaults in agroup_vars/allfile. SeeOrganizing host and group variablesfor details on how to organize host and group variables in your inventory. You generally place group variables alongside your inventory file, but they can also be returned by dynamic inventory (seeWorking with dynamic inventory) or defined in AWX or on theRed Hat Ansible Automation Platformfrom the UI or API:
Set location-specific variables ingroup_vars/my_locationfiles. All groups are children of theallgroup, so variables set here override those set ingroup_vars/all:
If one host used a different NTP server, you could set that in a host_vars file, which would override the group variable:
Set defaults in roles to avoid undefined-variable errors. If you share your roles, other users can rely on the reasonable defaults you added in theroles/x/defaults/main.ymlfile, or they can easily override those values in inventory or at the command line. SeeRolesfor more info. For example: