Last Updated: February 25, 2016
·
917
· destructuring

Putting chef cookbooks into RubyGems

Each reuseable cookbook of mine is a GitHub repository that is also a RubyGem. It can be managed by Bundler as a gem file or a git url in the Gemfile.

Since chef's cookbook_path configuration item takes an array, you can examine all the gems loaded by Bundler (say a few dozen rubygem cookbooks).

Something like this to loop through $: and check for a cookbooks directory:

cookbook_path $:.collect {|x| File.join(File.expand_path("..", x), "cookbooks") }.select {|x| File.directory? x }

Once cookbooks are packaged as gems, you might as well add cucumber features, rspec tests, rake tasks, etc. and start treating cookbooks as just another Ruby library project.

I don't know how this works with Chef Server. I deploy chef-solo like any other application using Capistrano.