|
Chef Solo allows you to run Chef Cookbooks in the absence of a Chef Server. To do this, the complete cookbook needs to be present on disk. 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 Configuring Chef Server and Clients, we use the following ~/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.
| Multiple Cookbooks Directories You can also specify cookbook_path as an array, passing multiple locations to search for cookbooks. 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. An example JSON file, which sets a resolv.conf:
(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.
Running from a Directory
Now that you have chef-solo configured for a directory, you can store the cookbooks there directly and run chef-solo against that directory.
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.
Or if you're using multiple cookbook directories (make sure you've modified the cookbook_path variable in solo.rb to include both paths as described above):
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!
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:
Simply remove the '-r URL', and the configuration file tells Solo where to look.
You can also specify the JSON data via URL.
| Config File is Optional You can create the solo.rb in /etc/chef/solo.rb instead, and chef-solo will look there by default, thus making the '-c ~/solo.rb' optional. |
| A Gentle Reminder Remember, Chef Solo is totally disconnected from the chef server. There is no authentication, no authorization, no search indexes, no persistent attributes. It's just the bare ability to execute Cookbooks. |
Roles
Chef Solo can also use Roles. They need to be in JSON format instead of Ruby DSL, and you need to tell the solo config file where the roles live. Using the earlier example:
The JSON file for the role would look something like:
Finally, the JSON data passed to chef-solo:
Note that this uses the run_list instead of recipes. See how to set the run_list in JSON.