Hi!
I tried to read up on everything I could find w.r.t. multi stage environments, but I haven’t found a solution that fits my needs yet.
Let’s say, I have 4 “environments”: dev, test, stage, production
And 2 “kinds” of servers: web, db
To simplify things, I only have on variable, the size of the “ram”.
In “dev”, “test” and “stage” the ram for “web” should be 1GB, and 4GB for “prod” (artificial example to show the issue!)
And in “dev”, “test” and “stage” the ram for “db” should be 2GB, and 8GB for “prod”:
dev test stage prod
±----------+ ±----------+ ±----------+ ±----------+
web | (1GB) | | (1GB) | | (1GB) | | (4GB) |
±----------+ ±----------+ ±----------+ ±----------+±----------+ ±----------+ ±----------+ ±----------+
db | (2GB) | | (2GB) | | (2GB) | | (8GB) |
±----------+ ±----------+ ±----------+ ±----------+
The roles are centrally defined (say ansible-galaxy), and I cannot use the defaults from the roles.
Possible solutions:
- I have an inventory for each stage, but then I have to maintain the “ram” variable duplicated everywhere,
although I have a useful default value for each “kind” of server. I do not know where to put the default “ram” for “web”
servers or for “db” servers:
├── dev/
│ ├── group_vars/
│ │ ├── db
│ │ └── web
│ └── inventory
…
└── prod/
├── group_vars/
│ ├── db
│ └── web
└── inventory
- I could merge the inventories, like this:
[db-prod]
[web-prod]
[db-dev]
[web-prod]
…[db:children]
db-prod
db-dev
…[web:children]
…[prod:children]
db-prod
web-prod[dev:children]
…
But the problem is that group precedence is alphabetically, I cannot express that “prod” has precedence over “web”
-
I could use the fact that group-vars in the inventory vars have lower precedence than group_vars in the file system, so that I define group vars for server “kinds” (db and web) in the inventory file and group vars for environment in the file system. But that feels rather artificial
-
I could use the alphabetical precedence of group names by using by using names like:
10env_dev 10env_test 10env_stage 10env_prod
20kind_db 20kind_web
but this is quite ugly.