Chef 12 has the notion of organizations
, and environments
.
How would you logically model different data centers?
For example, if you have two data centers, with 2 environments.
us-datacenter
\_ production
\_ stage
eu-datacenter
\_ production
\_ stage
Each environment has web servers that need to point at different databases
us-prod-web01 => us-prod-db01
eu-prod-web01 => eu-prod-db01
us-stage-web01 => us-stage-db01
eu-stage-web01 => eu-stage-db01
The obvious answer would be to create nested databags which contain the ip addresses of the correct database.
$datacenter/$environment/web
$datacenter/$environment/database
However databags have a strict 2 level hierchy, and there is no concept of a 'datacenter' that I can find.
How could this best be modeled? The two approaches I can think of.
Use 2 level databags
$environment/us-web
$environment/us-database
$environment/eu-web
$environment/eu-database
This has the downside of putting a lot of databags in one directory. Even if you use the gui with hosted CHEF, thats still hard to scroll through databags. (8 data centers * 4 environments * 6 types of webservers + 2 types of database servers = a lot )
- Put a data center variable in the role / node attributes and write a helper method to look up the correct databag.
This was suggested on IRC, however writing a helper method seems very complex (being new to chef, and having never done anything like this). Also it seems like it is a lot of reinventing the wheel for a use case that should be very common. For example, this can be done simply in puppet+hiera
Surely I'm not the first person using chef to have different settings in different datacenters.