Vagrant / Chef - 未找到食谱

Vagrant / Chef - Cookbook not found

我正在尝试为 Chef 提供 vagrant VM,但我不断收到以下消息:

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

我当前的 default.rb 文件如下:

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

我的元数据文件如下:

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"

我当前的 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

知道如何解决这个问题吗?

你的metadata.rb状态:

name             "Test Machine" 

您的食谱应位于名为 "Test Machine" 的文件夹中,而不是 "sis"。或者您的 metadata.rb 必须更新。

花点时间 learning chef 来了解食谱写作的基础知识。

你没说你用的是哪个版本的chef所以我没法给更多建议

元数据中的 name 应该显示菜谱的名称。文件夹名称是什么,您的食谱所在的位置并不重要。

你的问题是你在食谱中有 "Test Machine" 食谱,但在 Vagrantfile 中包含 "sis" 食谱。在 metadata.rb 中将名称更改为 "sis" 或在 Vagrantfile 中将 chef.add_recipe "sis" 更改为 chef.add_recipe "Test Machine"

如果您的食谱位于 cookbooks/sis/recipes/default.rb 然后像这样使用:

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

如果您有多个文件,例如 cookbooks/sis/recipes/file1.rb...file2.rb 然后使用:

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

还要保持正确的食谱路径,您可以提供完整的食谱路径,例如:

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.