Switch branches/tags
Nothing to show
Find file History
Pull request Compare This branch is 5 commits behind stevendanna:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.


Shef Scripts and Helpers

This directory includes scripts and helper classes that I have found helpful when debugging problems. Unlike this exec folder, the scripts here focus on tools I typically need when working interactively in Shef.


Adding the following to the configuration file you will be using with Shef (such as your knife.rb or shef.rb file) will place ~/src/knife-hack in Ruby's load path, allowing you to more easily use the libraries in the shef directory.

unless defined?(Shef).nil?
  $: << File.expand_path("~/src/knife-hacks/")

Raw API Requests

raw_request.rb creates a raw_api object that is similar to the api object, but shows you the raw JSON that the API returns rather than returning a Chef object. Often, by creating a Chef object (such as a Chef::Node object) from the API response, the default api object hides possible problems with API responses.

To use this:

require 'shef/raw_rest'
raw_api = ShefRawREST.new(Chef::Config[:chef_server_url])

Shef Extras

The ShefExtras library provides features that make interactive debugging in Shef a bit easier.


require 'shef/extras'

Recipe Mode

The majority of the features in ShefExtras are relevant in recipe-mode.


setup_run provides an easy way to debug problems with an existing node. setup_run starts a chef run, expands the node's run_list, and places the resources in the resource_collection.

require 'shef/extras'
# Now in recipe mode
# We've now loaded all of our recipes
# And started a chef run.  We can step through it.


ordered_resources prints the list of resources in the order chef will run them.

insert_break(preposition, resource)

insert_break allows you to insert a breakpoint before or after a resource in the resource_collection.

chef:recipe > pp ordered_resources
["log[a]", "log[b]", "log[c]"]
chef:recipe > insert_break :before, "log[c]"
[Sat, 28 Jan 2012 19:19:28 -0800] INFO: Breakpoint added before log[c]
chef:recipe > insert_break :after, "log[a]"
[Sat, 28 Jan 2012 19:19:37 -0800] INFO: Breakpoint added after log[a]
chef:recipe > pp ordered_resources

This is most useful when you have used setup_run to load the resources from a node's run_list.

DoppelGanger Fix

doppelganger_fix contains a monkey-patch that fixes CHEF-2869 and allows you to use become_node. This is a temporary fix until the problem is resolved in Chef.