How to test modified chef recipe on single node

chef

I have a chef server managing a handful of nodes. The server has recipes and data bags with various secrets. I'd like to make changes to one of the recipes and test it on a single node only: I do not want other nodes to update and use the modified recipe.

Solutions I have explored:

Test Kitchen, etc.

Tests are nice, but there are some details I cannot test without the data bags and other things unique to the chef server.

rsync code into /var/chef/cache/cookbooks

And run chef-client --skip-cookbook-sync

This fails because my cookbook source code lacks a metadata.json and various other things.

bump the cookbook version, upload, edit node's run list

This is difficult to coordinate concurrent work among multiple developers (particularly if testing lasts days or weeks). There are also several environments outside my control, and I can't really assume they're all locked to a particular version of the cookbook I wish to modify.

rename cookbook, upload to server, apply alternate role to node

This is the solution I'm using for now. It's tedious because changing the cookbook name changes the names of any resources it defines, so I've got to edit the cookbook quite a bit. Maintaining the alternate role set to use the renamed cookbook is also an annoyance.

Best Answer

I've handled that by setting the cookbook version to something like 0.0.1 and locking just the target environment to that version -- this avoids causing everyone with an unlocked environment to adopt the new cookbook.

If you need it to be truly a specific node, you could create a dummy cookbook that 'depends' on your specific 0.0.1 cookbook and assign that recipe as an additional runlist entry to a node. As long as the environment's pin allows for older cookbooks (ie <= x.y.z instead of = x.y.z) then it'll force that one node to use the special cookbook.

Also, look at test-kitchen + chef-zero to test server features inside the kitchen.

Related Topic