Delicious new Chef Sugars

A few months ago, I blogged about a thing called Chef Sugar. To quickly refresh your memory, Chef Sugar is an extension of the Chef core, recipe DSL, and select resources designed to make life as a Chef engineer as awesome as possible.

I first wrote Chef Sugar for incredibly selfish reasons - I was really sick of seeing the same patterns repeated across all of our cookbooks. It all started with the shell extensions

read more

The future of Vagrant Berkshelf

There seems to be some confusion about this post. We are deprecating vagrant-berkshelf, a plugin for integration Berkshelf with Vagrant. We are not depecating Berkshelf by any means.

After some internal discussions and conversations with the community, we are now looking for a new maintainer for the vagrant-berkshelf plugin. If you are interested in being part of the Berkshelf core team and managing the vagrant-berkshelf plugin, please contact me or anyone on the Berkshelf core

read more

Chef recipe code coverage

How do you do code coverage with Chef?

This seems like a simple question and should have a really simple answer. Chef recipes and resources are just Ruby code afterall, so a tool like Simplecov should do the trick...


During a chef-client run, Chef dynamically loads (and reloads) resources at runtime. Tools like Simplecov rely on parsing Ruby's AST tree to determine when a particular line of code is executed. But, if that file

read more

Handle Faraday::Error::ConnectionFailed with middleware

Faraday is a really nice, middleware-based HTTP client for Ruby. For simple libraries, I recommend HTTParty, but Faraday is a really awesome solution when you need full control over the complete stack.

However, Faraday has one feature/flaw that I have found. If Faraday is unable to connect to a server, it throws a really nasty error. I whipped up a tiny middleware to handle this error:

class Middleware::Exceptions < Faraday::Middleware  
  def call
read more

Changing Chef Resources at Runtime

As the cookbook wrapper pattern becomes more prevalent, you may find it necessary to alter a parameter of a Chef resource in the library cookbook. For example, you may need to update the cookbook from where a file should be found, execute an action before a service starts, or change the variables passed to a template.

If you care not to dig into the Chef internals, I highly recommend Bryan Berry's Chef Rewind. But if

read more

Berksfile Magic

The Berksfile is really one of the most magical compontents of Berkshelf - a cookbook dependency manager for Chef. As a core team member, I sometimes take for granted the extensibility of Berkshelf, so I decided to blog about some patterns!

Because the Berksfile is evaluated as Ruby, you have the ability to write pure Ruby code that will be evaluated at runtime.

Company Cookbooks

Just like any standard Ruby class, you can define custom

read more

Using gems with Chef

Installing gems with Chef is relatively painless. Most of the time, you can use the gem_package resource, which behaves very similarly to the native package resource:

gem_package 'httparty'  

You can even specify the gem version to install:

gem_package 'httparty' do  
  version '0.12.0'

You may have also seen the chef_gem resource. What's the difference?

The chef_gem and gem_package resources are both used to install Ruby gems. For

read more

Using Amazon Opsworks with Berkshelf

Amazon Opsworks supplies its users with a nice collection of starter cookbooks on GitHub. Berkshelf prefers users treat each cookbook as its own software project, but for Opsworks users, that is not an option. Let me demonstrate a few ways you can use Berkshelf in tandem with Amazon Opsworks.

There are two common ways to force Berkshelf to use the "monolithic repo" mode. Please note: you should only follow this approach if you absolutely have

read more

Spice up your recipes with Chef Sugar

A few months ago, I was having a discussion with some colleagues internally and CHEF-494 came up. In short, the ticket was created by Seth Chisamore and proposed creating a core cookbook that included some useful primitives for common patterns:

We need a cookbook that contains helpful libraries that would useful across all cookbooks...

The comment thread went on with suggestions of methods and solutions, including ubuntu_before_lucid?, best_ip_for, vagrant helpers, and

read more

Authorizers, Extractors, and Policy objects

Recently I was working on a Rails 4 project, and much to my surprise, my favorite authorization framework is not supported! CanCan had long been my "go-to" framework for its simplicty and readability. I started searching the Internet for alternative gems, but many of them were also "not-Rails-4-ready" or had not had activity in months. Then I stumbled across this awesome blog post from the fine ladies and gentlemen at Elabs and was thoroughly impressed

read more