0

I'm trying to understand how to organize my Chef kitchen and extend the functionality of Opscode community cookbooks. Disclaimer: n00b.

PLANNED STACK

  • Ubuntu 12.04.2
  • Apache2 (package)
  • PHP 5.4.13 (compiled)
  • MySQL Server
  • MySQL Client

APACHE COOKBOOK + COMPILED PHP

The Apache cookbook only offers a recipe for installing php as a package. The official Ubuntu 12.04 package installs PHP 5.3 and there is no good unofficial 5.4+ package. The application requires PHP 5.4+. Therefore, PHP must be compiled from source with the "--with-apxs2" flag.

APXS

To compile PHP to work with Apache2 requires apxs2 (or apxs), which doesn't appear to be installed by the apache::default recipe (even though apache2 -l shows mod_so.c and the apache docs seem to indicate that this indicates installation.)

  1. I did notice that line 142-143 of the default apache.conf.erb template has a commented out LoadModule line with something about "keeping apxs happy", but I didn't understand its purpose. Is there something simple I'm missing in the Apache2 docs that shows how to install or enable apxs?
  2. The Apache cookbook doesn't offer a method for installing the dev package. So where should this installation occur? My 'sample_lamp_app' recipe? In a cookbook like 'my_apache2' that "extends" the community cookbook? The 'php::source' recipe, with a not_if conditional that test for apxs?

NOTE

Please don't answer with things like "upgrade to Ubuntu 12.10" or "use this unofficial Apache2 cookbook instead". First, the project spec requires 12.04. Second I'm more interested in learning the proper methods for organizing and interacting within cookbooks.

0

I asked this same question to one of the guys from Opscode at a conference a couple of weeks ago..

We currently use an old version of chef (10.14.4) because it allows you to store cookbooks in multiple locations and chef will merge them all together. When you do this, it warns of deprecated behavior but the Opscode guy didn't seem to have an answer for the correct way to do it.

Directory structure

We override only the parts we want to change, and the metadata file. In this case, we've copied the default.rb file, made changes and saved it in our cookbooks-overrides directory. Note that we also copied over metadata.rb, in which we've bumped the version number. I usually prepend a 9, so that my version is always the highest, making the version something like 92.2.13 instead of 2.2.13. In this way, I use the 9 as a type of namespace.

`-- chef
    |-- cookbooks
    |   `-- apache2
    |       |-- attributes
    |       |   `-- ...
    |       |-- CHANGELOG.md
    |       |-- CONTRIBUTING.md
    |       |-- definitions
    |       |   `-- ...
    |       |-- files
    |       |   `-- ...
    |       |-- Gemfile
    |       |-- LICENSE
    |       |-- metadata.json
    |       |-- metadata.rb
    |       |-- README.md
    |       |-- recipes
    |       |   `-- ...
    |       `-- templates
    |           `-- ...
    `-- cookbooks-overrides
        `-- apache2
            |-- metadata.rb
            `-- recipes
                `-- default.rb

knife.rb

We tell Chef where to look for the cookbooks

...
cookbook_path [
    "#{ENV['HOME']}/dev/deployment/chef/cookbooks",
    "#{ENV['HOME']}/dev/deployment/chef/cookbooks-overrides"
]

Now when you push the cookbook to your chef server with knife cookbook upload , you'll get a warning because the cookbook exists in more than one place, but it will still happily merge them together and you'll end up with one cookbook which does what you want.

This is, I'm sure, not "the way" to do it, but it's certainly one way which as been successful for us so far. It just takes a bit of diligence to make sure your overrides still work when you update the underlying cookbook (in this case, apache2).

Other references

This post talks about creating a 'wrapper cookbook' to do what you want.

This post talks about a tool to manage third party cookbooks.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.