How to install a cookbook on a per-environment basis?

[In this message, I'm formulating the problem on a generic form; although we don't have many environments and many "extra" cookbooks, I'd still like to know the generic solution]

Our infrastructure is configured with a few different environments.

We'd like to be able to install ("extra") cookbooks on a per-environments basis, that is, certain environments should have certain cookbooks, while not certain others.

What's the general pattern to achieve that (excluding the obvious ugly solution of writing conditionals)?

There are only a couple of clean solutions I can think of.

The first is not to associate extra cookbooks with environments, but to specify them at provisioning time, in the runlist.

I think this is a fair solution, although, I'd like to shift the complexity entirely in the Chef domain.

The other (sort of creative) solution I can think of is to store empty versions of the extra cookbooks, say, and to associate those versions to environments where we don't want to have those cookbooks. This way they'll run, but do nothing.

Are there established solutions for this problem?


Policyfiles will be your best friend.