Debugging Chef

We have a pretty elaborate Chef setup where I work.  We use the open source Chef Server where the nodes get their configuration and recipes.  Everything is version controlled, automatically tested, and deployed via a controlled process.  But all those controls can slow down development.  Sometimes you just want to hack up an idea up on a real machine before investing the time to code up a solution, write tests, run style checks, version all the things, feed it through the CI pipeline, and ultimately deploy to tons of nodes.  (Since we have an simple re-imaging process, screwing up the node configuration via manual hacking is NBD.)

I have found chef-shell a great tool for doing this sort of thing.  It’s a simple matter to log in to a node and run chef-shell -z to start up an interactive ruby shell that loads (and runs) the recipes that the node would normally run when you do chef-client.  The nice part is you can tweak a recipe and re-run it.  For example, I had a recipe that was failing:

windows_zipfile "#{cache_path}/Downloads/drivers/usb3_#{node['nuc']['usb3_driver_version']}" do
 source node['nuc']['usb3_driver_url']
 action :unzip
 not_if { ::File.exist?("#{cache_path}/Downloads/drivers/usb3_#{node['nuc']['usb3_driver_version']}") }
end

package 'Intel(R) USB 3.0 eXtensible Host Controller Driver' do
 source "#{cache_path}/Downloads/drivers/usb3_#{node['nuc']['usb3_driver_version']}/Intel(R)_USB_3.0_eXtensible_Host_Controller_Driver_3.0.5.69/Setup.exe"
 action :install
 version '3.0.5.69'
end

The package install was returning ‘1’ instead of ‘0’, but providing no stdout/stderr.  I suspected this was a non-standard installation package, so I wanted to try it as a :custom package.  I simply had to enter chef-shell’s “recipe mode”, get a reference to the existing resource, modify it, and run it:

recipe_mode
x = resources("package[Intel(R) USB 3.0 eXtensible Host Controller Driver]")
x.installer_type = :custom
x.options = '-s'
x.run_action(:install)

This worked, although I found the return code was 14 (which means reboot required for this installer) so I went ahead and coded it up as:

package 'Intel(R) USB 3.0 eXtensible Host Controller Driver' do
 source "#{cache_path}/Downloads/drivers/usb3_#{node['nuc']['usb3_driver_version']}/Intel(R)_USB_3.0_eXtensible_Host_Controller_Driver_3.0.5.69/Setup.exe"
 action :install
 options '-s'
 installer_type :custom
 version '3.0.5.69'
 returns [0, 14]
end

References

Timberman, J. (2014, July 21). Load_current_resource and Chef-shell [Web log post]. Retrieved November 30, 2016, from http://jtimberman.housepub.org/blog/2014/07/21/load-current-resource-and-chef-shell/

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s