Ohai Chefs!
If you do enough Vagrant testing, you’ll soon run into a Vagrant box with an outdated Chef client. Even the Opscode Test Kitchen boxes come with Chef 10.14.4, not the latest 10.16.2 version. In this post I’ll show you how to automatically upgrade the Chef client on vagrant up
. The trick is to use two config.vm.provision
blocks in your Vagrantfile.
Download the Opscode Chef-Client cookbook and add an Upgrade recipe
You’ll need a Chef recipe to upgrade your Chef client. Below is a recipe we added to our fork of the Opscode Chef-Client cookbook.
1 2 3 4 5 6 |
|
We’re using Windows in this case but obviously, use the Chef client for your platform. We’ve successfully used this pattern with Linux boxes as well.
In your Vagrantfile
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
|
OK, but two Chef runs? Really?
“But, why can’t you just use a single provision block and add the Chef Client upgrade recipe to the first position in the run list?”
That was my question the first time Kevin showed me this pattern. He explained,
“Because, Chef will complete the Chef run with the same version it started with.”
In other words, the first Chef run starts with 10.x and upgrades itself. The second Chef run starts with the new, shiny, upgraded client.
Credit Where Credit is Due
Once again, mad props to my Talented and Gifted™ teammate for figuring this out. This really helped us out when we were stuck with a RHEL 5.8 Vagrant box with Chef 10.8 and needed to test Chef recipes written for Chef 10.16.2.
Ladies and Gentlemen, 'vagrant up'
Now everytime, you vagrant destroy
and vagrant up
, you’ll have the latest Chef Client without having to crack open and repackage your Vagrant box. Happy testing and let me know how it works for you.