Chef is a configuration management framework that allows you to easily create and manage a system configuration. One of the key values of using Chef is you can write configuration management scripts and deploy those configurations through Chef regardless of the underlying OS. Your configurations are deployed and managed through a Chef "cookbook".
In this topic:
You can install Chef as a client or as a stand-alone system known as Chef-solo. Chef-solo does not include some of the key features of the Chef system but does allow you to run "cookbooks" against your machine.
Before you can install Chef, you need to install Ruby and RubyGems first. Both of these are available in the SmartMachine package repository.
- Run this command to install Ruby:
- Check to see if RubyGems is installed:
If RubyGems is installed, you should see the installed package version number. If RubyGems is not installed, follow these steps:
- Change directories to the /tmp directory:
- Download the RubyGems package:
- Decompress the RubyGems package:
- Change directory to the RubyGems directory:
- Install RubyGems:
- Update RubyGems:
This command updates every installed gem on the system. The update process can take several minutes.
You are now ready to install Chef on your system by running the following command:
|Chef requires installation of gcc. If you receive an error about a missing gcc command when attempting to install Chef, run this command then try to install Chef again:|
You use a Chef cookbook to distribute your configuration management. A cookbook is further broken up into components such as attributes, definitions, and recipes that perform actions resulting in your desired configuration. You can store cookbooks locally or store them remotely in a repository such as git.
|For more information on Chef cookbooks, see the official Chef cookbook documentation.|
When using Chef-solo, you need to specify two key pieces of information.
The Chef configuration file contains Chef configuration data. The main purpose for the Chef configuration file is to point out to Chef where you store your cookbooks. For Chef-solo, you can only run cookbooks from a local directory. So, you need to setup the directory structure and then define the path to cookbooks in your Chef configuration file.
Two lines in your Chef configuration file define where you store your cookbooks:
file_cache_path and cookbook_path. You can define any path you like for these with two exceptions:
- The paths you define must be absolute.
- The directory you define for cookbook_path must be a subdirectory of the directory you define for file_cache_path.
To point Chef at your configuration file, use the -c or -config option. For example:
If you do not specify a file, Chef defaults to pulling your configuration from /etc/chef/solo.rb.
|An easy way of defining Chef configuration data is by storing it in /etc/chef/solo.rb. Chef pulls configuration data from that location by default and you will not need to specify a file.|
For Chef-solo, you define attributes and recipes in a JSON file instead of on a Chef server. Like cookbooks, you can store this file locally or in a remote repository.
- Attributes: Attributes are data that apply to your resources. For example, the IP address, hostname, loaded kernel modules, version of programming languages available on the system and so on.
- Recipes: Recipes are the fundamental configuration in Chef. Recipes encapsulate collections of resources that execute in the order you define to configure the system.
|For more information on configuring Chef-solo, see the official Chef-solo documentation.|
Below are a couple examples of Chef cookbooks. These cookbooks are hosted as github projects, which is considered a best practice for maintaining a cookbook.
This cookbook installs and configures a MySQL client or server.
This cookbook installs and configures a Jira client or server and starts it as a service under runit.
This cookbook installs and configures WordPress per the instructions here.
|This cookbook does not setup a WordPress blog. You need to do that manually.|