Chef 11 has come out, and possibly broken a bunch of your carefully crafted cookbooks. How are you going to test them, though? Here’s one way, using chef-solo via Vagrant.
- RVM (or rbenv, but this will use RVM)
- some cookbooks you wrote and want to test
Set it up
We don’t want to mess up our carefully crafted Chef 10.x environment, right? We’ll use rvm gemsets to make a disposable set of gems. If something goes wrong, just close the terminal you’re in, or run
rvm gemset use default. You’ll drop back to the default gemset.
DO NOT install RVM if you already use rbenv. They’re incompatible, and you don’t want to mess with that.
1 2 3 4
NOTE: update the homebase = to be the full path to your homebase.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
Do some magic
At this point, you should have an ubuntu 12.04 machine starting up, using Chef 11.2.0. It’ll run the apt::default recipe (assuming you have it), and throw errors if there are any.
chef.add_recipe "foo::bar"to add a recipe
chef.add_role "baz"to add a role
If you’re used to environments, you can run
knife environment show <envname> --format json to get an environment as json from your chef-server. You can also do
knife node show <nodename> -a node -f j to get all of the attributes from a particular node you already have. This gist can be adapted to get your json into the ruby ‘hashrockets’ syntax. Then you’ll need to update the
chef.json in your Vagrantfile with your attributes.
What about test-kitchen?
As of this writing test-kitchen’s master branch doesn’t support Chef 11. Once it does, you should definitely use it.