Chef, Ops, Ruby, Linux/Unix. Opinions are mine, not my employer's (CHEF).
Quick Tip: Alternative Chef Shell With Pry
This quick tip brought to you by the letters “p,” “r,” and “y.”
You can start up a pry session in the context of a Chef recipe easily by using chef-apply. The pry gem is bundled with the Chef omnibus package, so it’s immediately available.
2.1.6 (#<Chef::Recipe>):0 > file "/tmp/hello_world" do
2.1.6 (#<Chef::Recipe>):0 * content "I'm in pry!"
2.1.6 (#<Chef::Recipe>):0 * end
This will return the file[/tmp/hello_world] resource. It doesn’t run Chef, but we can do that in one of two ways: exit pry, or send the create action to the resource.
If we write multiple resources, we’d have to send that action to every one of them. Exiting pry will work, but then we are, of course, no longer in the pry session. This is not ideal, but hey, it’s not like we’re in chef-shell.
However, it may be useful to debug things through the Chef Server API. We will want to do two things. First, load a config file like .chef/knife.rb. We can verify the Chef Server we want is configured by checking Chef::Config[:chef_server_url].