Testing Chef Cookbook changes

I recently worked on a Chef Cookbook development. I learned a very nice and useful way to test my changes without affecting any other Cookbooks, applications. I have explained it below. I am still a beginner at this, let me know if you are aware of a better approach

Let’s assume that we need to make changes in cookbook named new-app, following is how I test changes:

Step 1: Check the available versions of a cookbook on chef server

knife cookbook show new-app

Step 2: Choose a very small version number x.y.z, smaller than the smallest number in output of previous command, I like to use 0.0.1

Step 3: In your local copy of cookbook, update the version number in metadata.rb file to x.y.z.

Step 4: Make the changes you intend to test.

Step 5: Upload the cookbook using following command

 knife cookbook upload new-app -o /path/to/cookbook's/parent/directory

Step 6: Test the cookbook specific version

6.1: If you use cookbook name in run list directly

chef-client -o 'recipe[new-app@x.y.z]'


6.2: If you provide run list arguments through json file

chef-client -j runlist.json




6.3 If you provide run list through role

chef-client -o 'role[new-app-role]'

Role definition

name "new-app-role" 
description "NEW APP SERVICE"
run_list "recipe[new-app@x.y.z]"

Step 7: After changes have been tested, delete the test version from server

knife cookbook delete new-app x.y.z -y 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.