Draco Ater
Draco Ater

Reputation: 21226

Organizing Chef Cookbooks For Different Servers

I have several different servers used for different purposes. Everyone use mysql, but it should be configured a little bit different. => Different users, different databases.

I have a cookbook that installes mysql.

The question is, where should I put the scripts that create databases and users for mysql?

Sould it be:

  1. One script for every server(role) inside mysql cookbook? (This way different configs for 1 server will be in different cookbooks)
  2. Create a cookbook for every role, where I concatenate all the special configurations concerning this role. (This way different configs for 1 server will be in 1 particular place, but we will have 1 additional cookbook)

I personally think the #1 is better, as we join the different cookbooks under I role anyway.

Edit

It does not concern only databases. For example, I have some applications that require tomcats/jetties/other containers to be installed and configured differently (different ports, different modules enabled). Where different versions of settings.xml/jetty.xml etc. should be stored? In cookbook that

  1. installs tomcat or
  2. that installs other application, that requires tomcat?

Upvotes: 4

Views: 948

Answers (2)

Jordan Dea-Mattson
Jordan Dea-Mattson

Reputation: 5821

This problem seems to be screaming out for you to use an environment and then have different data bag entries based on environment.

I would place these servers in the appropriate environment, matching the settings they have.

Alternately, the proposal you have around roles also makes sense.

Upvotes: 0

jarrad
jarrad

Reputation: 3292

I would suggest including the Opscode database cookbook which provides a LWRP for managing databases and database users.

Next, I would suggest creating one generic cookbook that leverages the LWRPs for databases and data bags. The data bags will hold your configuration information and will isolate your per server configuration differences.

This will allow you to define your data for each server (users, databases, etc) and write one cookbook that can pull in the data and use it.

Also, check out the encrypted data bags which allows you to store your passwords in an encrypted form on your Chef server.

Upvotes: 5

Related Questions