Ansible 2.0 variable precedence using an inventory file

Hi all,

I have a set of Ansible configuration that I intend to use as a Generic template for setting up a Django webserver and related services. This project contains a multitude of roles for configuring various aspects optional services (Nginx, Django, Redis, Postgres, etc.).

I’m trying to find a good way to specify good global default, overridable variables that can be used throughout all of my roles. For example, I’d like to define variables like “app_user” or “app_name” (and many others) that I can use in all of my roles.

Right now, these variables are placed at the top level of my project inside of env_vars/base.yml. I’m thinking that this would be my global default configuration file that would define all of the defaults throughout the project and inform users of what settings are available to override.

Also, the role defaults that I have defined in each role read in variables set in the env_vars/base.yml (my global defaults file), and set local copies of those variables for use in that role’s tasks.

contents of roles/postgres/defaults/main.yml

Generally the best place to put global vars you want to override is in role defaults. These have the lowest priority and can be very easily overridden by just about any other variable source, including inventory variables (so I’m not sure what problem you’re running into there). You should be able to specify the db_user var in either group or host vars, or in params set on the role as it’s being run (or even --extra-vars, in the extreme case).