Cláudio Ribeiro
Cláudio Ribeiro

Reputation: 1699

Vagrant / Chef - Cookbook not found

I'm trying to provision a vagrant VM with chef but I keep getting the following message:

"ERROR: cookbook sis not found. If you're loading sis from another cookbook, make sure you configure the dependency in your metadata."

My current default.rb file is the following:

bash "apt update" do
code "apt-get update"
end

# manually install php 5.5....
execute "yum install -y --skip-broken php55w php55w-devel php55w-cli php55w-snmp php55w-soap php55w-xml php55w-xmlrpc php55w-process php55w-mysqlnd php55w-pecl-memcache php55w-opcache php55w-pdo php55w-imap php55w-mbstring"

bash "install mysql-server 5.1.69" do
user "root"
cwd "/tmp"
code <<-EOH
groupadd mysql
useradd -r -g mysql mysql
cd /usr/local
wget http://cdn.mysql.com/Downloads/MySQL-5.1/mysql-5.1.69-linux-i686-glibc23.tar.gz
tar zxvf mysql-5.1.69-linux-i686-glibc23.tar.gz
rm mysql-5.1.69-linux-i686-glibc23.tar.gz
ln -s mysql-5.1.69-linux-i686-glibc23 mysql
cd mysql
chown -R mysql .
chgrp -R mysql .
scripts/mysql_install_db --user=mysql
chown -R root .
chown -R mysql data
cp support-files/my-medium.cnf /etc/my.cnf
cp support-files/mysql.server /etc/init.d/mysql.server
EOH
not_if do
File.exists?("/etc/my.cnf")
end
end

bash "start mysql-server 5.1.69" do
user "root"
code <<-EOH
sudo /etc/init.d/mysql.server start
/usr/local/mysql/bin/mysql -e 'GRANT ALL ON *.* TO root;'
EOH
end

And my metadata file is the following:

name             "Test Machine" 
maintainer       "Claudio"
maintainer_email "******"
license          "All rights reserved"
description      "Installs/Configures sis"
long_description IO.read(File.join(File.dirname(__FILE__), 'README.md'))
version          "0.0.1"

My current Vagrantfile:

# -*- mode: ruby -*-
# vi: set ft=ruby :

Vagrant::Config.run do |config|
# All Vagrant configuration is done here. The most common configuration
# options are documented and commented below. For a complete reference,
# please see the online documentation at vagrantup.com.

# Every Vagrant virtual environment requires a box to build off of.
config.vm.box = "precise32"

# The url from where the 'config.vm.box' box will be fetched if it
# doesn't already exist on the user's system.
config.vm.box_url = "http://files.vagrantup.com/precise32.box"
config.vm.customize ["modifyvm", :id, "--memory", 512]
config.vm.network :hostonly, "192.168.100.10"
#config.vm.provision :shell, path: "bootstrap.sh"


# Enable provisioning with chef solo, specifying a cookbooks path, roles
# path, and data_bags path (all relative to this Vagrantfile), and adding 
# some recipes and/or roles.
#
config.vm.provision :chef_solo do |chef|
 chef.cookbooks_path = "./cookbooks"
 chef.roles_path = "./roles"
 chef.data_bags_path = "./data_bags"

 #hef.add_recipe "sis"
 #chef.add_role "web"

  # You may also specify custom JSON attributes:
  chef.json = { :mysql_password => "foo" }
  end

end

Any idea on how can I solve this problem?

Upvotes: 0

Views: 665

Answers (3)

pl_rock
pl_rock

Reputation: 15782

if your recipe located at cookbooks/sis/recipes/default.rb then use like:

chef.cookbooks_path = "cookbooks"
chef.add_recipe "sis::default"

if you have multiple file like cookbooks/sis/recipes/file1.rb...file2.rb then use like:

chef.add_recipe "sis::file1"
chef.add_recipe "sis::file2"

also keep correct cookbooks path you can give fullpath of cookbooks like:

chef.cookbooks_path = "/home/user/fullpath/cookbooks" 

cookbooks_path (string or array) - A list of paths to where cookbooks are stored. By default this is "cookbooks", expecting a cookbooks folder relative to the Vagrantfile location.

Upvotes: 0

Draco Ater
Draco Ater

Reputation: 21226

The name in metadata should show name of the cookbook. It does not really matter what the folder name is, where your cookbook is situated.

Your problem is that you have "Test Machine" cookbook in cookbooks, but include "sis" recipe in Vagrantfile. Either change name to "sis" in metadata.rb or change chef.add_recipe "sis" to chef.add_recipe "Test Machine" in Vagrantfile.

Upvotes: 0

Tensibai
Tensibai

Reputation: 15784

Your metadata.rb state:

name             "Test Machine" 

Your cookbook should reside in a folder named "Test Machine", not "sis". or your metadata.rb have to be updated.

Take some time on learning chef to get over the basics of cookbook writing.

You don't say which version of chef you're using so I can't give more advice.

Upvotes: 0

Related Questions