Question

i'm struggling with the chef recipes for a vagrant box. I'm using chef-solo.

I'm not so comfortable with Ruby (i've never used it before), so the process to write my recipes is very long if i have to do vagrant provision each time.

Is there a way to debug a specific recipe? Even from the virtual machine shell.

I've seen that chef-shell exists (http://docs.opscode.com/chef_shell.html), and i can launch it (it works) when i'm inside the virtual machine, but i can't understand how to load my recipes and test them.

Was it helpful?

Solution 4

You can use chef-solo directly from the shell inside your VM but this requires a different file structure than what you have for vagrant already.

It's looks a bit like what is done here:

  • You need your cookbooks directory
  • You need a .json file containing all your data that resides in chef.json in your Vagrantfile
  • And you need a wrapper/startup ruby script like the one from the post above.

In general try to search for tutorials that explain chef-solo without Vagrant.

OTHER TIPS

The proper way to enable debug output in the current vagrant chef provisioner is with chef.log_level, not with chef-solo manually or with chef.arguments:

Vagrant.configure("2") do |config|
  # ...
  config.vm.provision :chef_solo do |chef|
    chef.log_level = :debug
    # ...
  end
end

In addition to the above input, which is execllent;-)

Runing chef-solo in debug mode (enable debug output) will definitely help.

For example

chef-solo -c solo.rb -j node.json -l debug

If you run chef-solo inside Vagrant additional custom arguments (for logging/debugging) can be injected from the Vagrantfile like this:

 Vagrant.configure("2") do |config|
    # ...
    config.vm.provision :chef_solo do |chef|
      chef.arguments = '-l debug'
      # ...
    end
 end
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top