Returning Customers — Login
Call 1.866.720.0208 or contact us
Table of Contents
Show a recommended developer workflow for developing ServerTemplates using Chef cookbooks and recipes.
There are two basic types of workflows for Chef development.
The rsync program is available on Linux machines and can be used to synchronize file trees across local disks, directories, or a local network. In this example, rsync will be used to synchronize the cookbook repositories on your local development box with the cookbook repositories on the running server instance.
Although you can use both workflows for Chef development purposes, some developers may find it more useful to use the rsync model. One of the key benefits of using the rsync workflow is that you can develop your code faster and more efficiently because you do not have to constantly push all of the changes to your repository and refresh them in the Dashboard before you can run and test the script on the server. By using the rsync model, you can author code on your local development machine and test the script immediately on the running server without having to perform the push and refetch steps every time. This way, you will only have to push the code changes after you have already tested them on a running server.
Note: If you are using the rsync model, you will never be able to refetch changes from your cookbook repositories. As a best practice, once you are satisfied with your changes after testing your scripts using rsync, you should commit the changes to your cookbook repositories and relaunch a fresh new server without the "development" tag (which is mentioned in more detail below).

Note: You must use this workflow if you are going to make any changes to the Chef metadata (e.g. Add a new recipe).

Note: You can only use this workflow if you are not going to make any changes to the Chef metadata (e.g. Add a new recipe).
rs_run_recipe -n "<cookbook_name>::<recipe>" && tailf /var/log/messages
When you launch a server that uses cookbooks for server configuration purposes, the required cookbook repositories are locally stored on the server instance itself. A unique identifier is assigned to each repository on a running server instance. You will need to know a repository's UID if you want to use the Chef Developer Workflow that uses rsync.
Launch a server that uses cookbooks for server configuration purposes.
Once the server is operational, SSH into the server instance and navigate to the directory where cookbooks are locally stored. If you are using a server that was launched with a RightImage the cookbooks will be stored in the following location: /var/cache/rightscale/cookbooks
Run the following command to navigate to the default location:
# cd /var/cache/rightscale/cookbooks
Each cookbook repository that is used by the server will be assigned a unique identifer. Therefore, you will most likely see a list of several cookbook directories.
# cd /var/cache/rightscale/cookbooks # ls 05fe0e9401da911fdb518fe37b3a8c5393e3883d 12fdb518fe37b3a8c5393e3283d05fe0e9401da9 b518fe37b3a8c5193e3883d05fe0e9401da912fd
Inside each one you will find a 'cookbooks' directory with all of the repository's cookbooks and recipes.
# cd 05fe0e9401da911fdb518fe37b3a8c5393e3883d/cookbooks/

To determine which Repository UID represents which repository, you might want to create a table for yourself:
| Repository Name | Repository UID |
| rs_premium | 05fe0e9401da911fdb518fe37b3a8c5393e3883d |
| rs_public | 12fdb518fe37b3a8c5393e3283d05fe0e9401da9 |
| my_custom | b518fe37b3a8c5193e3883d05fe0e9401da912fd |
Use this code example to create a RightScript or Chef Recipe. Add it to the HEAD ServerTemplate as an operational script so that it will be easily accessible for script execution. Later, when you're ready to commit the ServerTemplate for production use, you can remove it from the ServerTemplate.
#!/usr/bin/env ruby
# rsync's current directory to your VM
#
# You must set CLOUD_KEY in you environment to point to your
# private SSH key file.
#
# Your VM must have the corresponding public SSH key in the
# ~/.ssh/authorized_keys file.
#
# RightScale can place your public key on the VM at boot if you
# set up your public key in the Dashboard with the
# "Use the credentials stored on my computer" option under
# Settings > User Settings > SSH.
#
host = ARGV[0]
path = ARGV[1]
raise "Usage: sync_to <host_ip> <dst_path>" unless host && path
SSH_KEY_PATH = ENV["CLOUD_KEY"]
puts "Syncing to #{host}..."
opts = "-avz --exclude=.git -e 'ssh -i #{SSH_KEY_PATH}'"
cmd = "rsync #{opts} . root@#{host}:#{path}"
puts "Command: #{cmd}"
puts `#{cmd}`
If you want to run the command locally on your development machine, see code example below.
<need code sample>
rsync from Local Development Machine to Cloud Instance
rsync -avz --exclude=.git <src_path> <dst_path>
where <scr_path> is the directory of where the cookbooks are locally stored on your development machine.
<dst_path> is the directory of where the cookbooks are locally stored on the cloud server instance.
<HASH> is the Repository UID.
EXAMPLE:
rsync -avz --exclude=.git /src/cookbooks/ ec2-50-19-197-20.compute-1.amazonaws.com:/var/cache/rightscale/cookbooks/<HASH>/cookbooks
# rsync -avz --exclude=.git /src/cookbooks/ ec2-50-19-197-20.compute-1.amazonaws.com:/var/cache/rightscale/cookbooks/05fe0e9401da911fdb518fe37b3a8c5393e3883d/cookbooks
If you want to run the command on the test instance, SSH into the machine and run the following commands. See the code example below.
<need code sample>