【问题标题】:Vagrant / Chef - Cookbook not foundVagrant / Chef - 未找到食谱
【发布时间】:2015-10-25 18:52:33
【问题描述】:

我正在尝试使用 Chef 配置一个 vagrant VM,但我不断收到以下消息:

“错误:未找到食谱 sis。如果您从另一个食谱加载 sis,请确保在元数据中配置依赖项。”

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

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

【问题讨论】:

  • 执行和 bash 步骤应该是厨师食谱中的例外。包资源例如处理 yum。
  • “sis”实际出现在您的代码中的什么位置?你只显示在食谱描述中,这不会引发错误。
  • 我在 cookbooks/sis 中有 sis 文件夹。 sis 文件夹包含 recipes 文件夹。
  • 那么,这个姐姐本身?即您粘贴在 cookbooks/sis/recipes/default.rb 中?你在用 berkshelf 吗?
  • 好的,所以首先我的依赖“sis”解决了 nada。我假设你在 使用 sis,而不是你在 on sis。其次,您的整个 recipes/default.rb 也有点离题 - 问题更可能在于您配置 Chef 和 Vagrant 的更广泛的方式。你的 Vagrantfile 是什么样的?您的 Berksfile 是什么样的(假设您使用的是 Berks)。事实上,在你的命令行上运行 chef --v 并将结果粘贴到你的帖子中,它会告诉我们你正在使用什么 Chef。

标签: vagrant chef-infra provisioning


【解决方案1】:

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

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

【讨论】:

    【解决方案2】:

    您的 metadata.rb 状态:

    name             "Test Machine" 
    

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

    花点时间在learning chef 上学习编写食谱的基础知识。

    你没有说你使用的是哪个版本的厨师,所以我无法提供更多建议。

    【讨论】:

      【解决方案3】:

      如果您的食谱位于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(字符串或数组)- 食谱的路径列表 被存储。默认情况下这是“食谱”,期待食谱 相对于 Vagrantfile 位置的文件夹。

      【讨论】:

        猜你喜欢
        • 2015-02-25
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-04-11
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多