Multi Dimension-Configuration

Hi,

I’m about to introduce Ansible in a bigger environment for a client.

We have the following dimensions:

  • Customer
  • Environment (Dev, Test, Int, Demo, Prod)
  • Applications / Versions

Which really means: if we have 6 Systems for Customer X in Integration, we again have 6 Systems for Customer X in Demo and again 6 in Prod…
and then the same applies to Customer Y and so on.

I figured: it would be a good start to have a directory for each customer with its own inventory for all the staging envs and a role directory which is shared among all customers (since we’re mostly deploying the same software):

ansible/
customerX
inventory
all
prod
int
test
customerY
inventory
all
prod
int
test
roles
appX
appY

This way, I was able to set some application default under “roles/appX/defailts/main.yml”, which can be overwritten under customerX/inventory/group_vars/ with customer specific values for example. So far so good.

The issue

There might be configuration which is valid for a certain staging environment, regardless of the customer. A simple example could be: the db server port in integration is always the same for all customers (but only in integration). My original idea was to “reference” the environment in a role by using group_vars - but that isn’t supported. I guess with some lookups and parametrized calls it would be possible to accomplish this in a playbook/role. But this seems rather cumbersome to maintain, especially when expecting additional applications over time.

Then I’ve added a dirty one line patch to lib/ansible/inventory/init.py to support a global group_vars dir at same level as my customer and shared role dir:
line 641:
basedirs.extend([self.basedir() + “/…/…/”])

This currently breaks the priority of the group_vars below the inventory directory, but I was able to do environment based configuration, as I wanted.

Example Inventory file “customerX/inventory/integration”:

[integration]
192.168.0.1
192.168.0.2

[frontend]
192.168.0.1

[backend]
192.168.0.2

So I’m able to set some variable under “ansible/group_vars/integration” and also under “ansible/customerX/inventory/group_vars/frontend” which is very helpful.
Probably I can set global defaults over all roles, customers, environments in “ansible/global_vars/all” (not tested yet).

So, my questions is: Is there really not other way to accomplish this, except writing a patch?

Kind regards,
Chris