|
IntroductionOpscode Team Member Sean OMeara put together a Brief Chef Tutorial on his personal blog. A portion of it is reproduced here, to provide an example... From concept to release ... the birth of a NTP Cookbook.Hello, NTP!A machine’s NTP client is simple to install and configure. Every systems administrator is already familiar with it, which makes it a great example. Most software available as a native package in a given linux distribution can be managed with a “package, template, service” design pattern. Each of those words refers to a Chef resource, which we pass arguments to. Step One : Creating an ntp cookbook
This creates a directory structure for the ntp cookbook. You can check it out with ls: Step Two : Deciding what to name the recipe
Recipe names are related to cookbook structure. Putting recipe[foo::bar] in a node’s run list results in cookbooks/foo/recipes/bar.rb being downloaded from chef-server and executed. There is a special recipe in every cookbook called default.rb. It is executed by every recipe in the cookbook. Specifying recipe[foo::bar] actually results in cookbooks/foo/recipes/default.rb, as well as cookbooks/foo/recipes/bar.rb being executed. Default.rb is a good place to put common stuff when writing cookbooks with multiple recipes, but we’re going to keep it simple and just use default.rb for everything. Step Three : Creating a recipe
This is where all the fun stuff happens. When using resources, you’re writing things in a declarative fashion. Declarative means you can concentrate on the WHAT without having to worry about the HOW. Chef will take care of that for you with something called a resource provider. When installing a package, it will check to see what your operating system is and use the appropriate methodology. For example, on Debian based systems, it will use apt-get, and on Redhat based systems, it will use yum. Chef recipes are evaluated top down (like a normal ruby program), with each resource being ran in the order it appears. Order is important. In the above example, if we were to reverse the order of those three resources, it would first fail to start the service (as the software is not installed yet), then write the configuration file, then finally clobber the file it just wrote by installing the package. Step Four : Creating the ntp.conf.erb template
Step Five : uploading the cookbook to chef-server
More?For more of the tutorial from Sean, see A Brief Chef Tutorial (from concentrate). For more information on any of the steps above, see the documentation reference listed.
|


