Package versions on chef

chef

We're deploying a multi-node PHP environment using chef.

I've written a couple of cookbooks for specific server roles, that install certain packages (mostly using the package manager) the application uses.

Now, what I would like is for chef to keep the packages on these nodes up-to-date. We have two environments: development and production. When, say, a new version of PHP comes out, I would like to test this new version on our development environment and then roll it out to production. My package definitions in the recipe for installing PHP looks like this:

package 'php' do
  action :install
  version '5.3.27'
end

What steps do I take when version 5.3.28 is released?

Best Answer

The best practice for chef is to always start with the same "going in" state. If you're deploying to the cloud, I would create an entirely new VM and deploy PHP from scratch.

If you don't have that luxury, then you're in a situation where you must maintain two known starting states. (1) No PHP is installed and (2) Old version of PHP is installed.

You can't chain them together where you always install 5.3.27 first, because that ruins the idempotency of that resource.

I would recommend a manual step where you uninstall 5.3.27 and start clean with a 5.3.28 chef install.

Lastly, I would recommend avoiding use of chef roles as much as possible. They cannot be versioned and make it difficult to update when you have both a development and production system sharing the same role (i.e. how do I change the role without effecting both environments?) Instead, consider using a parent cookbook to orchestrate.

Related Topic