[chef] Including Cookbooks Conditionally


Chronological Thread 
  • From: Chad Woolley < >
  • To: Chef < >
  • Subject: [chef] Including Cookbooks Conditionally
  • Date: Sat, 24 Apr 2010 10:45:40 -0700
  • Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:from:date:message-id:subject:to:content-type; b=Xcg2UbG/3VoJ9yk08lqITIDOah9tyhAsSHUB3I0bcAewZ0jrgHKA1vHFqyha9Y2UVR LobabpPcfkyRJeykT+L3z7Nfed3LDV/pIVOc+SyMBwteVFiG2Psmxxt9UJzsQ87P9xF4 saNxCPUOXTwbmzpcu8nsoeBs01DXaKB3E6bNk=

Hi,

New to chef, and trying to get my head around best practices.

I'm using Chef to automate the building of EC2 AMI images (from an EC2
instance).  This is a bit of a special case, because I'm running chef
from within a chroot environment, so I can't start services.

So, I can see four categories of cookbooks I need:

A. Third party cookbooks
B. My own original cookbooks to perform specific tasks (e.g.
installing required dev packages)
C. Cookbooks which perform necessary overrides to third party
cookbooks (e.g. I find a bug in the third party cookbook)

These first three categories are "normal", and should be able to run
in the chroot environment, and also be run to update/fix EC2 images
which are created from the built AMI.  However, the fourth is a
special case:

D. Cookbooks which perform overrides to third party cookbooks, in
order to prevent services from automatically
starting/stopping/restarting (which will fail in a chroot env).

Obviously, I only want to include this category when I'm building the
AMI, but not when running normally on an instance started from the
AMI.

So, questions:

* Does anything sound wrong about this approach
* How should I organize these cookbooks?  I can have a custom repo,
which includes all the third-party cookbooks (A) as submodules, and
the others (B,C,D) checked in directly.  However, I would want to
conditionally exclude "D" from running if I'm not in a chroot
environment.

Seems like I want to use "Roles" here to do some conditional logic
based on whether I'm in chroot env or not, but I'm not sure what it
should look like.  I'm not even really sure where to stick the logic.
Right now I just have cookbooks listed in the 'cookbook_path' array in
node.rb.  I'm having problems finding detailed examples online which
are similar to what I want to do.  Pointers to docs/examples would be
greatly appreciated.

Thanks,
-- Chad



Archive powered by MHonArc 2.6.16.

§