Note: Please go to to access the current RightScale documentation set. Also, feel free to Chat with us!
Home > Guides > Chef Cookbooks Developer Guide > End User > Getting Started > Beginner Chef Tutorial

Beginner Chef Tutorial


To understand how to modify an existing ServerTemplate to use cookbooks and recipes from another Chef cookbook repository.

Table of Contents


  • RightScale account with valid cloud credentials
  • 'designer', 'actor', 'library', 'security_manager' user role privileges
  • Basic understanding of Chef


This tutorial assumes that you have a basic understanding of Chef and RightScale. It's recommended that you complete the Introduction to Chef Tutorial prior to starting this tutorial.

In this tutorial you will perform the following tasks:

  • Clone and update a RepoPath
  • Clone and update a ServerTemplate to use a custom RepoPath
  • Run Chef recipes from the new cookbook repository on a running server


Upon completion of this tutorial you will have a basic understanding of how Chef cookbooks and recipes can be used in the RightScale platform to launch and configure servers using ServerTemplates.  


Create a Deployment

Create a new deployment that you will use to launch a server later in this tutorial (e.g. Beginner Chef Tutorial).  See Create a New Deployment.

Import Cookbooks

The next step is to import a new cookbook that you want to use in a ServerTemplate.

  1. Go to Design > Repositories > New.
  2. Add the following sample repository that contains a few prebuilt cookbooks that you can use for this tutorial.
    • Name - Provide a user-friendly name. (e.g. RS Example Cookbooks)
    • Description - Provide a brief description about the repository. 
    • Type - Select 'Git' from the drop-down menu.
    • Tag/Branch - Enter 'master' for this value.
    • URL - Enter 'git://'
    • Git SSH Key - Ignore this field because the cookbooks are in a publicly visible repository. Note: Git SSH Keys are only required for retrieving cookbooks from private repositories.
    • Cookbook Paths - Enter 'cookbooks' for this value and click Add.
  3. Since you want to use the cookbooks in this repository, keep the checkbox checked (default) to automatically import all of the repository's cookbooks to the Primary Namespace. 
  4. Click OK. You should have imported the following cookbooks into the RightScale account.
    • hello_world
    • httpd
    • notifies

Import and Clone a ServerTemplate

Find the ServerTemplate that you want to customize. For this tutorial you will use the "Base" ServerTemplate published by RightScale, which is recommended if you are building a new custom ServerTemplate from scratch. However, the same customization steps will apply if you want to modify any existing ServerTemplate so that it can use Chef cookbooks from a specific repository.

  1. Go to the MultiCloudMarketplace (Design > MultiCloud Marketplace > ServerTemplates) and import the latest revision of the following ServerTemplate:
  2. Clone the ServerTemplate and rename it accordingly. (e.g. My Base)
  3. Commit the ServerTemplate, so that the first committed revision of the ServerTemplate matches the original version that it was cloned from, which will make it easier to perform a differential and track your changes to the ServerTemplate. Leave a simple commit message. (e.g. original version; no changes)

Attach a Cookbook to a ServerTemplate

  1. Go the Scripts tab of the editable HEAD version of the ServerTemplate.
  2. Click Modify.
  3. Click Attach Cookbooks.
  4. Find and select the 'hello_world' cookbook, which you imported into the RightScale account in a previous step. If more than one version of the cookbook is listed, select the version that is in the "primary" namespace and click Attach Selected.

Add a Recipe to the ServerTemplate

Now that the 'hello_world' cookbook is attached to the ServerTemplate, you can add any of its Chef recipes into one of the boot/operational/decomission sections of the ServerTemplate. 

  1. Under the Scripts tab of the HEAD version of the cloned ServerTemplate (e.g. My Base), find the 'hello_world' cookbook in the right-hand pane.
  2. Expand the cookbook to see its recipes. Drag and drop the cookbook's "default" recipe ('hello_world::default') to the bottom of the ServerTemplate's Boot Sequence.


Create and Launch a Server

You are now ready to create and launch a server using the modified ServerTemplate.

  1. Go to the the HEAD version of the cloned ServerTemplate (e.g. My Base).
  2. Click the Add Server button to add a server to your deployment (e.g. Beginner Chef Tutorial). Be sure to use the HEAD version (not rev 1) of the ServerTemplate because you want to be able to make changes to the ServerTemplate's Scripts tab so that you can test them on the running server. See the Add Server Assistant page if you need help adding a server to a deployment. Select or create any required cloud resources (e.g. SSH Key, Security Group, etc.). Name the server accordingly. (e.g. My Beginner)  
    To complete all exercises in this tutorial, you must launch the server using an Ubuntu RightImage. The default RightImage for the ServerTemplate is a CentOS 5.6 RightImage, so in the "Hardware" section of the Server Details tab of the "Add Server Assistant" wizard, you must select an Ubuntu RightImage from the "MultiCloud Image" drop-down menu.
  3. Launch the server. If you see a warning message that some cookbooks are missing, you can ignore this message because the missing cookbooks are not used by any of the recipes in the ServerTemplate. All of the inputs for any required scripts in the Boot Sequence should already be predefined at the ServerTemplate level so you shouldn't have to set any values. Click the Launch button.
  4. Once it becomes operational, go to the server's Audit Entries tab.  The last script that was run in the boot phase was the "Hello World" script.  Verify that the script was executed successfully. 

Tip:  To find the specific audit entry click on the link as shown above in the Summary column, expand on the Details in the Converging section, then use your browser Search (^F) feature.

Run an Operational Script

Now you're going to add a couple other Chef recipes and run them as operational scripts. Remember, a server's list of scripts always reflects what is defined by its ServerTemplate. Since the running server was launched with an editable HEAD version of a ServerTemplate, we can easily add a couple operational scripts to the ServerTemplate and execute them on the running server. (Note: The 'Any Script' option only exists for RightScripts. An equivalent feature is currently not supported for Chef recipes.)

Note: You can also safely add a RightScript to a ServerTemplate that uses Chef Recipes. For a more detailed example, see Using RightScripts with Chef Recipes.

  1. Go to the cloned ServerTemplate that you used to launch the running server.
  2. Go to the Scripts tab of the editable HEAD version of the ServerTemplate. Click Modify.
  3. Click Attach Cookbooks.
  4. Find and select the 'httpd' and 'notifies' cookbooks (which you previously imported to your RightScale account in an earlier step along with the 'hello_world' cookbook.
  5. Under the Scripts tab, add the following Chef recipes as operational scripts. The scripts you are going to add are in the httpd cookbook. Since these are operational scripts that will be executed on-demand, the order of the scripts is not important.
    • install_httpd
    • setup_index_page


  1. Go the running server's Scripts tab and run the install_httpd operational script. To view the actual code that is executed on the server, you can view the script on GitHub. (view recipe)
  2. Once install_httpd has completed, go to the running server's Info tab and click the Public DNS name link or copy and paste the server's public IP address into a browser window to view the basic Apache package that was installed on the server by the Chef recipe.  (Note:  If you tried to view the server's public IP address prior to running the install_httpd script you would have received an "Unable to connect" message in your browser.)
  3. Now you'll run the other operational script to replace the default index page with a customized version that will display your name. Go back to the server's Scripts tab and run the setup_index_page operational script. This particular script has a Chef attribute.
    View the script on GitHub. (view recipe)
    Chef attributes are treated as inputs. For this particular script, you will need to provide your name before the script can be run. Enter your name and click Continue.  (Tip:  Remember to change the drop-down from "Unset" to "Text" and then enter your name.)
  4. Once the script is successfully run, refresh the preview page in your other browser window to view the new, custom index page.

Congratulations! You have successfully completed this tutorial. You learned how to modify an existing ServerTemplate by attaching additional cookbooks and running new recipes.

Post Tutorial Steps

Terminate the Server

Don't forget to terminate your server when through using it to avoid any unwanted costs. 

Intermediate Chef Tutorial

To learn how to set up a basic Chef development environment and learn how to create a repository of your own cookbooks, see the Intermediate 1 Chef Tutorial.

You must to post a comment.
Last modified
11:05, 15 Apr 2014



This page has no classifications.



© 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.