Overview
While the Recipes installed with the Chef run can be customized, which occurs during the preparation stage in v5 and later, the main Recipes applied each time are essentially the same. These are called from ey-init::main, which is the starting point of the Chef run.
In this article we will explain how cookbooks are applied in the core Chef run. Please note that the v7 stack will be used for this example.
Contents:
The core Chef run
The process to execute a Chef run is detailed below, and follows through the steps outlined in the ey-init::main recipe:
- Chef reads the dna.json file and executes
ey-init::main. The following steps are called from this file. ey-base::resin_gemsprovides the base gems required by Chef. While the AMI (Amazon Machine Image) deployed contains some Gems already, Gems deployed via Recipe are easier to change and maintain.ey-coreinstalls some other important requirements for the following steps.ey-custom::before-mainare custom Recipes applied before the main Chef recipes run. This is not normally used for custom Recipes, and requires a higher level of knowledge, as it is prone to break things.-
ey-base::bootstrapincludes the main Recipes, creates the required directories, config files, etc.- It uses dna.json data to fill in multiple variables, such as the app name, choice of apps, versions, etc.
- The last line of the Recipe will execute ruby based on the contents of json.dna. This is because in v6 and v7 there are two Ruby versions; one for the application, and one for Chef. Running
ruby -vwill show the version of Ruby.
- The next line,
node.engineyard.instance.roles.each { |role| include_recipe "ey-#{role}::prep" }, will install Recipes specific to the instance role (application, DB, or utility). ey-base::post_bootstrapwill install additional Recipes after setting the required role Recipes.ey-custom::after-mainis the custom Recipes added after the main Chef runs. This is the normal place for custom Recipes to be added.- Finally,
ey-base::customwill add extra Recipes based on the environment variables set in the system.
Cookbook syntax
To understand the Chef recipes, it is useful to know some of the commands used:
include_recipe “<recipe>”: Imports another Recipe. This will import default.rb form within the Recipe folder.include_recipe “<recipe>::<file>”: Imports any other file than default.rb from the Recipe folder.execute “<command>”: This will define and execute a command, unless the action is set to "nothing", in which case it will only be defined.package “<app>”: Installs a certain package at the operating system level.
Note that dna.json is accessed by the Recipes to get information required to install them:
- "node" is the object used by Chef to configure the Chef run, which Enzyme amends with dna.json.
- It is navigated like any JSON object. The syntax used can be one of the following, or a combination of the two:
node.engineyard.environmentnode[“engineyard”][“environment”]
Summary
Cookbooks in Engine Yard are applied in the order described by ey-init::main, and can be debugged accordingly by understanding the anatomy of the core Chef run.
Priyanka Bhotika
Comments