Chef, Ops, Ruby, Linux/Unix. Opinions are mine, not my employer's (CHEF).
ChefDK and Ruby
Recently, Chef released ChefDK, the “Chef Development Kit.” This is a self-contained package of everything required to run Chef, work with Chef cookbooks, and includes the best of breed community tools, test frameworks, and other utility programs that are commonly used when working with Chef in infrastructure as code. ChefDK version 0.1.0 was released last week. A new feature mentioned in the README.md is very important, in my opinion.
Using ChefDK as your primary development environment
What does that mean?
It means that if the only reason you have Ruby installed on your local system is to do Chef development or otherwise work with Chef, you no longer have to maintain a separate Ruby installation. That means you won’t need any of these:
(*note: You can optionally use chruby with ChefDK if it’s part of your workflow and you have other Rubies installed.)
Do not misunderstand me: These are all extremely good solutions for getting and using Ruby on your system. They definitely have their place if you do other Ruby development, such as web applications. This is especially true if you have to work with multiple versions of Ruby. However, if you’re like me and mainly use Ruby for Chef, then ChefDK has you covered.
In this post, I will describe how I have set up my system with ChefDK, and use its embedded Ruby by default.
Getting Started
Download ChefDK from the downloads page. At the time of this blog post, the available builds are limited to OS X and Linux (Debian/Ubuntu or RHEL), but Chef is working on Windows packages.
For example, here’s what I did on my Ubuntu 14.04 system:
OS X users will be happy to know that the download is a .DMG, which includes a standard OS X .pkg (complete with developer signing). Simply install it like many other products on OS X.
For either Linux or OS X, in omnibus fashion, the post-installation creates several symbolic links in /usr/bin for tools that are included in ChefDK:
These should cover the 80% use case of ChefDK: using the various Chef and Chef Community tools so users can follow their favorite workflow, without shaving the yak of managing a Ruby environment.
But, as I noted, and the thesis of this post, is that one could use this Ruby environment included in ChefDK as their own! So where is that?
ChefDK’s Ruby
Tucked away in every “omnibus” package is a directory of “embedded” software – the things that were required to meet the end goal. In the case of Chef or ChefDK, this is Ruby, openssl, zlib, libpng, and so on. This is a fully contained directory tree, complete with lib, share, and yes indeed, bin.
12
% ls /opt/chefdk/embedded/bin
(there's a bunch of commands here, trust me)
Of particular note are /opt/chefdk/embedded/bin/ruby and /opt/chefdk/embedded/bin/gem.
To use ChefDK’s Ruby as default, simply edit the $PATH.
Note that this is the current stable release of Ruby, version 2.1.1 patchlevel 76, and the {almost} latest version of RubyGems, version 2.2.1. Also note the Gem paths – the first is the embedded gems path, which is where gems installed by root with the chef gem command will go. The other is in my home directory – ChefDK is set up so that gems can be installed as a non-root user within the ~/.chefdk/gems directory.
Installing Gems
Let’s see this in action. Install a gem using the gem command.
1234567
$ gem install knife-solve
Fetching: knife-solve-1.0.1.gem (100%)
Successfully installed knife-solve-1.0.1
Parsing documentation for knife-solve-1.0.1
Installing ri documentation for knife-solve-1.0.1
Done installing documentation for knife-solve after 0 seconds
1 gem installed
And as I said, this will be installed in the home directory:
Then I can use for example the rake task to preview things while writing this post.
1234567
$ ./bin/rake preview
Starting to watch source with Jekyll and Compass. Starting Rack on port 4000
directory source/stylesheets/
create source/stylesheets/screen.css
[2014-05-07 21:46:35] INFO WEBrick 1.3.1
[2014-05-07 21:46:35] INFO ruby 2.1.1 (2014-02-24) [x86_64-linux]
[2014-05-07 21:46:35] INFO WEBrick::HTTPServer#start: pid=10815 port=4000
Conclusion
I’ve used Chef before it was even released. As the project has evolved, and as the Ruby community around it has established new best practices installing and maintaining Ruby development environments, I’ve followed along. I’ve used all the version managers listed above. I’ve spent untold hours getting the right set of gems installed just to have to upgrade everything again and debug my workstation. I’ve written blog posts, wiki pages, and helped countless users do this on their own systems.
Now, we have an all-in-one environment that provides a great solution. Give ChefDK a whirl on your workstation – I think you’ll like it!