To understand where Chef cookbooks are stored.
Note: This document describes functionality that is supported by RightImages v5.7 and newer.
Table of Contents
Chef cookbooks are stored in several locations. It's important to understand the relationship between each one, as well as where the cookbooks are actually stored in each location.
Relationship Diagram
If you are developing your own Chef cookbooks or modifying existing ones, you will need to have a machine that you will use for Chef development purposes. Typically, you will either configure your own laptop or use a server in the cloud. When you create and modify Chef cookbooks on your development machine you will regularly push changes up to your repositories that are hosted on your source control management system (e.g. GitHub).
The most commonly used source control management system for hosting Chef cookbook repositories is GitHub. (http://github.com) RightScale uses GitHub to store all of its own cookbook repositories. However, you can use other source control management systems (e.g. SVN) to host your Chef cookbooks.
Repose is RightScale's own repository caching service for hosting Chef cookbooks and other assets that are used by ServerTemplates to launch and configure servers in the RightScale management platform. See Repose.
When you launch a server using ServerTemplates, the cookbooks that are required by the scripts of a Chef run list will be retrieved from Repose and saved locally to the instance. Only the cookbooks (and any cookbook dependencies) that are required to execute a Chef run list will be copied to the server instance. When you launch a server, only the cookbooks that are required to run the boot script list (as defined by the ServerTemplate) will be copied to the instance. Cookbooks that are required by operational or decommission scripts will only be copied to the instance if and when they are needed to execute a queued run list. For subsequent Chef runs on an instance, any existing cookbooks may be overwritten, but will never be deleted.
To view where they are stored, you can SSH into an instance and navigate to the following locations:
The 'chef' directory contains content required to execute a Chef run on the instance.
In this directory you will find a list of all the cookbooks that were required to run the most recently executed Chef run list. The run list could consist of a single recipe (e.g. Operational Script) or a runlist that consists of multiple recipes (e.g. Boot/Decommission Sequence). For example, if you look at this directory after launching a server (who's ServerTemplate contained Chef recipes in its Boot Sequence) for the first time, you will see a SHA for each cookbook that was used in the boot sequence. In the example below, 8 different cookbooks were used. Notice how each cookbook is located in a directory based upon the SHA it's assigned in Repose. The selection of cookbooks that are retrieved from Repose and downloaded to this directory on the instance is based upon the cookbooks attached to the ServerTemplate.
# cd /var/cache/rightscale/cookbooks/default # ls 0f00a4137d32727689073eb6c6d9ef2d 6107f8979a4a6d6e3a207d3bea25a3c8 285e6c48a8d5cbea487c44a17c40885e b127fc13b6e1e1bdd142c70360e2cc82 3c2e825a89052cb719ebb346dd6d3ab7 b6c7b4d885241287542bc8639cdf740f 4fb6f36944e2aa2236ae9ba924a024f2 f5ed36fd7a463f2261029d84232dd5cf # ls 0f00a4137d32727689073eb6c6d9ef2d iptables
The contents of this directory will be updated each time a single script or series of scripts (e.g. boot/decommission sequence) is executed on the server. Note: If you run a RightScript (not a Chef recipe) as an Operational Script, the contents of the above directory will be deleted.
Remember, a recipe can depend on variables set by recipes in other cookbooks. Therefore, in order for a recipe to run successfully on an instance, any cookbook dependencies will also be retrieved and copied to the instance's local disk. For example, if you run 'app::setup_app' and it references a recipe ('db::setup_db') from another cookbook, both the 'app' and 'db' cookbooks are copied in their entirety to the instance. In such cases, a cookbook's metadata must clearly declare any cookbook dependencies.
Note: Cookbook dependencies are defined in a cookbook's metadata. See Chef Metadata for details.
There may be scenarios where a ServerTemplate contains both RightScripts and Chef recipes. In such cases, each RightScript will ultimately be run as a Chef recipe as part of a Chef run list. For RightScripts that are listed in the boot or decommission scripts list inbetween Chef recipes, they will be executed in the correct, sequential order as they are listed under the ServerTemplate's Scripts tab. RightScripts are converted into Chef recipes and saved to the instance's local disk in this directory. Two files will be created for each RightScript.
© 2006-2014 RightScale, Inc. All rights reserved.
RightScale is a registered trademark of RightScale, Inc. All other products and services may be trademarks or servicemarks of their respective owners.