ChefDK Ruby integration with RBenv or RVM

Three Rubies and a ChefDK

Joaquín Menchaca (智裕)
2 min readMar 13, 2018

--

ChefDK requires that you use their embedded ruby for running the Chef tools, but you may already have an existing ruby workflow that uses RBenv or RVM.

If the only time you use ruby is when you use Chef tools, there will come a time when you find your Chef code is no longer compatible with a recent release of ChefDK. This has even happened recently with the arrival of Chef 13.

In this later scenario, you will need to manage different versions of ruby to support different versions of Chef. Some of your cookbooks will be pinned or locked to use legacy version of Chef, while others will use a newer version. This is where you’ll need to find a way to integrate a tool such as RVM or RBenv to support switching between ChefDK and another ruby environment that supports the legacy Chef environment.

So there you have it, you have three ruby environments, and this guide briefly walks you through each of these:

  • Use ChefDK’s embedded ruby for everything
  • Integrate ChefDK with rbenv ruby manager.
  • Integrate ChefDK with RVM (ruby version manager)

Installing ChefDK

If you have not done so already, install ChefDK:

On Windows, you can use a tool like Chocolately to fetch ChefDK: choco install -y chefdk.

On Mac OS X, you can use Brew Cask to install ChefDK: brew cask install chefdk.

ChefDK Embedded Ruby

If you do not use ruby outside of Chef, then just using the embedded ruby is fine. Chef can automate setting up your shell environment:

RBenv Integration

With RBenv, there’s a ChefDK plug-in that can point back to ChefDK.

The next time you log-in, you can run the following, and test for chef before and after switching to chefdk:

$ rbenv which ruby
/home/vagrant/.rbenv/versions/2.3.6/bin/ruby
$ gem list | grep 'chef\s'
$ rbenv global chefdk
$ rbenv which ruby
/opt/chefdk/embedded/bin/ruby
$ gem list | grep 'chef\s'
chef (13.8.5)

RVM Integration

With RVM, we scissor in symlinks point back to chef’s embedded ruby.

Afterwards, we can select chefdk ruby, or use another ruby. Here’s testing before and after.

$ rvm use
Using /home/vagrant/.rvm/gems/ruby-2.3.6
$ gem list | grep 'chef\s'
$ rvm use chefdk
Using /home/vagrant/.rvm/gems/ext-chefdk-ruby
$ gem list | grep 'chef\s'
chef (13.8.5)

ChefDK in Projects

If you need to use ChefDK in your chef repository for all cookbooks, or maybe just a single cookbook, you can use .ruby-version mechanism to lock the version of ruby in that directory.

cd /path/to/your/cookbook
echo chefdk > .ruby-version

Afterward, any time you enter that directory, you’ll automatically be switched into ChefDK.

Links

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

Joaquín Menchaca (智裕)
Joaquín Menchaca (智裕)

Written by Joaquín Menchaca (智裕)

DevOps/SRE/PlatformEng — k8s, o11y, vault, terraform, ansible

Responses (1)

Write a response