Chef Solo - Run chef without a server.
Get started - RailsCasts Chef Solo Basics
- Chef Solo
- First Chef Solo Run Manually
- Berkshelf - Manage Cookbook Dependencies
- Food Critic
- Use knife-solo to create directory structure ("kitchen")
- Vagrant + Chef Solo
First Chef Solo Run Manually
Create cookbook directory structure
cookbooks directory structure
Create a recipe in main (also a recipe)
and a more complicated screenfetch.rb
About Providers, see more at => Resources and Providers
The following providers are available. Use the short name to call the provider from a recipe:
|Long name||Short name||Notes|
|Chef::Provider::Package||package||When this short name is used, Chef will attempt to determine the correct provider during the Chef run.|
|Chef::Provider::Package::Apt||apt_package||The apt_package resource is used to manage packages for the Debian and Ubuntu platforms.|
|Chef::Provider::Package::Dpkg||dpkg_package||The dpkg_package resource is used to manage packages for the dpkg platform. When a package is installed from a local file, it must be added to the node using the remote_file or cookbook_file resources. Can be used with the options attribute.|
|Chef::Provider::Package::Pacman||pacman_package||The pacman_package resource is used to manage packages for Arch Linux.|
|Chef::Provider::Package::Rpm||rpm_package||The rpm_package resource is used to manage packages for the RPM Package Manager platform. Can be used with the options attribute.|
|Chef::Provider::Package::Rubygems||gem_package||The gem_package resource is used to manage gem packages that are only included in recipes. When a package is installed from a local file, it must be added to the node using the remote_file or cookbook_file resources. Can be used with the options attribute.|
|Chef::Provider::Package::Rubygems||chef_gem||The chef_gem resource is used to install a gem only for Chef resources. When a package is installed from a local file, it must be added to the node using the remote_file or cookbook_file resources. Can be used with the options attribute.|
|Chef::Provider::Package::Yum||yum_package||The yum_package resource is used install, upgrade, and remove packages with yum for the Red Hat and CentOS platforms. The yum_package resource is able to resolve provides data for packages much like yum can do when it is run from the command line. This allows a variety of options for installing packages, like minimum versions, virtual provides, and library names.|
NOTE: Recommended to use knife-solo to create cookbooks directory structure.
Chef Solo Configuration file
Create chef-solo configuration file
NOTE: if the nodes are behind firewall (HTTP Proxy required to access the Internet), configure http proxy (can be used in both client.rb and solo.rb), see http://docs.opscode.com/config.html
In solo.rb, add
For example, the solo.rb for Chef run within Oracle network
Another example from Chef Server's embedded Chef Solo run
Its configuration file
NOTE: Cookbooks are in /opt/chef-server/embedded/cookbooks
A complete solo.rb ready to eat
Node Objects - JSON file
Attributes and run-list, including overriding default attributes in the cookbook (attributes/default.rb)
Run - let's cook!
NOTE: The cookbook_path does NOT have to be /var/chef/cookbooks, as long as the directory structure is maintained and configured correctly in solo.rb.
Berkshelf - Manage Cookbook Dependencies
Add a Berksfile to cookbook’s root
NOTE: run the command in the directory where Berksfile resides
Add Berksfile to the project
NOTE: A Berksfile.lock will also be created. Add this to version control if you want to ensure that other developers (or your build server) will use the same versions of all cookbook dependencies.
Use berkshelf to create a skeleton for a new cookbook
directory tree structure
More about Berkshelf
A lint tool for Opscode Chef Cookbooks.
Foodcritic has two goals
- To make it easier to flag problems in your Chef cookbooks that will cause Chef to blow up when you attempt to converge. This is about faster feedback. If you automate checks for common problems you can save a lot of time.
- To encourage discussion within the Chef community on the more subjective stuff - what does a good cookbook look like? Opscode have avoided being overly prescriptive which by and large I think is a good thing. Having a set of rules to base discussion on helps drive out what we as a community think is good style.
Food Critic Rules http://acrmp.github.io/foodcritic/
Use knife-solo to create directory structure ("kitchen")
knife-solo adds a handful of commands that aim to make working with chef-solo as powerful as chef-server. It currently adds 5 subcommands to knife:
- knife solo init
used to create a new directory structure (i.e. "kitchen") that fits with Chef's standard structure and can be used to build and store recipes.
- knife solo prepare
installs Chef on a given host. It's structured to auto-detect the target OS and change the installation process accordingly.
- knife solo cook
uploads the current kitchen (Chef repo) to the target host and runs chef-solo on that host.
- knife solo bootstrap
combines the two previous ones (prepare and cook).
- knife solo clean
removes the uploaded kitchen from the target host.
Run knife solo init
NOTE: Directory structure may change as development continues. More can be added by hand: attributes, files, libraries, templates etc.
Vagrant + Chef Solo
The chef solo provisioner allows you to provision the guest using Chef, specifically with Chef Solo.
Chef solo is ideal for people who are already experienced with Chef, already have Chef cookbooks, or are looking to learn Chef. Specifically, this documentation page will not go into how to use Chef or how to write Chef cookbooks, since Chef is a complete system that is beyond the scope of a single page of documentation.
Specifying a run list
This causes Vagrant to run Chef Solo with the "apache" cookbook. The cookbooks by default are looked for in the "cookbooks" directory relative to your project root.
NOTE: What is a Vagrantfile?
Custom cookbook path
Instead of using the default "cookbooks" directory, a custom cookbooks path can also be set via the cookbooks_path configuration directive
The path can be relative or absolute. If it is relative, it is relative to the project root.
The configuration value can also be an array of paths
Vagrant also supports provisioning with Chef roles. This is done by specifying a path to a roles folder where roles are defined and by adding roles to your run list
Just like the cookbooks path, the roles path is relative to the project root if a relative path is given.
Data bags are also supported by the Chef Solo provisioner. This is done by specifying a path to your data bags directory
Custom JSON Data
Additional configuration data for Chef attributes can be passed in to Chef solo. This is done by setting the json property with a Ruby hash (dictionary-like object), which is converted to JSON and passed in to Chef
Hashes, arrays, etc. can be used with the JSON configuration object. Basically, anything that can be turned cleanly into JSON works.
Custom Node Name
Specify a custom node name by setting the node_name property. This is useful for cookbooks that may depend on this being set to some sort of value.