Skip to end of metadata
Go to start of metadata



Chef Solo allows you to run Chef Cookbooks in the absence of a Chef Server.

To provide the raw execution of cookbook recipes, the complete cookbook needs to be present on the disk.


Chef Solo does not provide:
  • Node data storage or search indexes.
  • Centralized cookbook distribution.
  • Environments, for setting policy of cookbook versions.
  • A central API to interact with and use to integrate infrastructure components.
This document will show you how to set up cookbooks and Chef Solo.


We're going to look at three of the options for chef-solo

And then we'll look at some examples of actually running chef-solo.

Configure Chef Solo

The first option is -c or --config, which takes a filename as a configuration file. If this option is not specified, by default Chef Solo will look in /etc/chef/solo.rb for its configuration. This configuration file has two required variables: file_cache_path and cookbook_path. For example, in our instructions for Chef Configuration Settings, we use the following ~/solo.rb:

~/solo.rb

For your own systems, you can change this to reflect any directory you like, but you'll need to specify absolute paths and the cookbook_path directory should be a subdirectory of the file_cache_path.

Please note: as mentioned below, the establishment of a Chef Repository will introduce considerations that you'll need to incorporate when determining your cookbooks directory structure. The result would determine use of the cookbook_path variable within ~/solo.rb.

Multiple Cookbooks Directories

You can also specify cookbook_path as an array, passing multiple locations to search for cookbooks.

~/solo.rb

Note that the order is significant, and changed in chef 0.8; earlier entries are now overridden by later ones. When you create the cookbooks tarball below, you'll need both directories to extract into the file_cache_path directory.

JSON, Attributes and Recipes

Since chef-solo doesn't have any interaction with a Chef Server, you'll need to specify node-specifc attributes in a JSON file. This can be located on the target system itself, or it can be stored on a remote server such as S3, or a web server on your network.

Within the JSON file, you'll also specify the recipes that Chef should run in the "run_list". An example JSON file, which sets a resolv.conf:

~/node.json

(See the opscode/cookbook, resolver)

Preparing your Cookbooks

You can point chef-solo at a target directory on the local system, or at a URL containing a tarball archive.

Chef Repository Interaction

If you are establishing a Chef Repository to define a location where cookbooks and other Chef artifacts will be stored and version controlled, please note the the Chef Repository will have considerations that you'll need to incorporate when setting up your chef-solo managed server and establishing the target directory that chef-solo is directed towards.

Running from a Directory

Once that you have chef-solo configured for a directory, you can store the cookbooks there directly and run chef-solo against that directory if that is the approach that you are undertaking.

Running from a URL

Running chef-solo against a URL containing a tarball is probably more common than running against a directory, however. First create the cookbooks tarball.

Creating a Chef Solo Tarball

If you're using multiple cookbook directories, note that chef-solo expects the tarball you give it to have a directory structure of the form:

    cookbooks/
       |---- cbname1/
              |--attributes/ ... etc
       ...
       |---- cbname2/
              |--attributes/
       ...

(See Rake Task "bundling cookbooks".)

Make sure you've modified the cookbook_path variable in solo.rb to include both paths as described above in Configure Chef Solo

Using Multiple Chef Cookbook Directories

Then, upload the resulting chef-solo.tar.gz to a web server that is accessible by the servers you wish to run chef-solo on. We do this for the bootstrap tarball that [Configures Chef Server and Clients].

Examples of Running chef-solo

Now that you have configured chef-solo, prepared JSON data for your system(s), and prepared your Cookbooks, it's time to run it!

Running Solo with URL

This actually uses the Chef remote_file resource type to retrieve the specified chef-solo.tar.gz into the file_cache_path, and extracts it to cookbooks_path, then runs Chef with those cookbooks. So once this has occurred, you can modify the cookbooks on the local system and rerun Chef with the directory:

Running Solo with Directory

Simply remove the '-r URL', and the configuration file tells Solo where to look.

You can also specify the JSON data via URL.

Running Solo with URL for Cookbooks and JSON

These two options, -r and -j correspond to the recipe_url and json_attribs config file options, respectively.

solo.rb

You can create the solo.rb in /etc/chef/solo.rb instead, as chef-solo will look there by default, thus making the '-c ~/solo.rb' optional.

Roles

Chef Solo can also use Roles. They can be defined in the JSON format or with the Ruby DSL, and you need to tell the solo config file where the roles live. Using the earlier example:

~/solo.rb

The JSON file for the role would look something like:

/var/chef-solo/roles/test.json

The above file using the Ruby DSL would look like:

/var/chef-solo/roles/test.rb

Finally, the JSON data passed to chef-solo:

~/chef.json

See how to set the run_list in JSON.

Environments

Currently chef-solo does not have support for environments.







Chef Client


Chef Server



Labels:
None
Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.