0

I probably got the whole concept wrong: I have a working Vagrant VM with Ubuntu 12.04, on top of it I want to install a few packages and config files. I have them set in Chef, in the path cookbooks/my_project/recipes I have a vagrant-dev.rb file with all the instructions. Now my Vagrant config in Vagrantfile must be the problem here:

config.vm.provision :chef_solo do |chef|
    chef.cookbooks_path = "cookbooks/my_project/recipes"
    chef.add_recipe "vagrant-dev.rb"
end

and when I load the VM I get

FATAL: Chef::Exceptions::CookbookNotFound: Cookbook vagrant-dev.rb not found.

I tried without the .rb at the end. I guess it's a completely different matter and I'm not using it the correct way. But after searching I couldn't find anything that explained how to do it properly.

Bastian
  • 283
  • 3
  • 16

1 Answers1

3

When using chef, all recipes must be in cookbooks. It looks like you might already have it in a cookbook, and are just calling it wrong, but I'll cover all of it, so you can double check.

Cookbooks are literally just a collection of recipe rb files, a bit of metadata, and optionally some other files (like templates, or databags). So you can't include the .rb file directly, you have to reference its cookbook, and then the name of the file (with out .rb) to run it.

A simple cookbook's structure should look like:

SomeCookbook
    readme.md # needed for the long_description in metadata to work
    metadata.rb # contains the actual information for the cookbook
    recipes # Holds all the cookbook's recipies
        default.rb # This is the default recipe, run if one isn't specified
        otherRecipe.rb
    templates # Templates that can be called by the cookbook
        default
            some-erb-style-template.erb

The name of the main directory doesn't matter, and the templates directory is optional.

metadata.rb

name             "SomeCookbook"
maintainer       "Me"
maintainer_email "support@me.com"
license          "None"
description      "Does something cool"
long_description IO.read(File.join(File.dirname(__FILE__), 'readme.md'))
version          "0.0.1"

supports "centos"

Follow the above structure, and make sure to stick your recipe into the recipes folder.
Then add this to your vagrant file:

chef.add_recipe "SomeCookbook::vagrant-dev"

Hope the above clears things up a bit.

Jess
  • 389
  • 1
  • 6
  • 16
  • great answer thanks, I needed to update my cookbooks path to just "cookbooks" in order for it to work but it's ok now the instructions are found and applied! – Bastian Sep 15 '13 at 20:44