chef-infra - 为什么 Chef 不能解决我的 Recipe ?

标签 chef-infra chef-recipe berkshelf

简介
我正在学习 Chef 来自动化工作中的服务器管理。
我从 here 下载了 Chefdk 3.0
现在我正在尝试使用厨师制作我的第一本食谱。

重要
我在 Windows 环境中使用它进行测试,我确实希望它失败,因为 Windows 没有 iptables,但我不希望它失败说它找不到食谱。我试过使用 Windows cookbook它有效。

问题
我能够创建食谱并运行它,但我无法从超市引用依赖项。

我尝试了两种选择:

备选方案 1

我使用以下命令来创建食谱

chef generate cookbook learn_chef_httpd

(来自 this tutorial)

我能够完成教程,现在我想测试引用另一本食谱,所以我选择了 simple_iptables

我添加了这一行
cookbook 'simple_iptables', '~> 0.7.0'

到我的 Berksfile,如超市中所述。

然后我将这些行添加到我的 default.rb 文件中:
include_recipe 'simple_iptables'

# Allow HTTP, HTTPS
simple_iptables_rule "http" do
  rule [ "--proto tcp --dport 80",
         "--proto tcp --dport 443" ]
  jump "ACCEPT"
end

我使用以下方法运行食谱:
chef-client --local-mode --runlist 'recipe[learn_chef_httpd]'

问题是厨师没有找到食谱
Chef::Exceptions::CookbookNotFound
----------------------------------
Cookbook simple_iptables not found. If you're loading simple_iptables from anoth er cookbook, make sure you configure the dependency in your metadata

我尝试将其添加到元数据中:
depends 'simple_iptables', '~> 0.7.0'

但我仍然收到一个错误:
Error Resolving Cookbooks for Run List:
Missing Cookbooks:

No such cookbook: simple_iptables

备选方案 2

我仍在努力使它工作,所以我也尝试使它成为“berkshelf方式”,所以我创建了一本新的食谱。
berks cookbook test

我添加了这一行
cookbook 'simple_iptables', '~> 0.7.0'

到我的 Berksfile,如超市中所述。

然后我将这些行添加到我的 default.rb 文件中:
include_recipe 'simple_iptables'

# Allow HTTP, HTTPS
simple_iptables_rule "http" do
  rule [ "--proto tcp --dport 80",
         "--proto tcp --dport 443" ]
  jump "ACCEPT"
end

执行 berks 安装:

berks install



并运行它:
chef-client --local-mode --runlist 'recipe[test]'

同样的错误又回来了
Chef::Exceptions::CookbookNotFound
----------------------------------
Cookbook simple_iptables not found. If you're loading simple_iptables from anoth er cookbook, make sure you configure the dependency in your metadata

我尝试将其添加到元数据中:
depends 'simple_iptables', '~> 0.7.0'

但我仍然收到一个错误:
Error Resolving Cookbooks for Run List:
Missing Cookbooks:

No such cookbook: simple_iptables

我查看了 ~/berkshelf 文件夹,食谱在那里。

** 备选方案 3 **

我在 Amazon 上启动了一个 CentOS 6.5 EC2 实例,安装了 Ruby 2.1.3 和 Chef。
创建了一个 ~/chef-repo/cookbooks 文件夹

我使用berkshelf创建了一本食谱,跑了
bundle install

添加了其他替代方案中的引用/代码
然后
berks install

和我上次一样跑。

我遇到了同样的问题。

我错过了什么?我需要什么才能使它工作?

最佳答案

确保您已配置您的 chef_repo_pathdocs 中所述.

基本上local-mode需要知道在哪里可以找到您的食谱、角色、环境、数据包等。遗憾的是,文档对您设置的位置/方式不是很清楚 chef_repo_path
这是我从代码中可以看出的。

  • 如果 client.rb找到并包含 cookbook_path , chef_repo_path = "#{cookbook_path}/.."
  • 如果 knife.rb找到并包含 cookbook_path , chef_repo_path = "#{cookbook_path}/.."
  • 厨师可以尝试占卜路径。 The code将从 pwd 开始搜索向上寻找名为cookbooks的目录.如果找到,则 cookbooks/..将设置为您的chef_repo_path。
  • 如果一切都失败了,pwd将用作您的 chef_repo_path

  • 如果您使用 Berkshelf,最好的办法是做一个 berks vendor为了获得一个目录,你需要的所有食谱。然后,您可以将chef_repo_path 指向cookbooks 的父级。保存您的供应商食谱的目录。

    请注意,这是挖掘源代码的 10 分钟,所以我可能不太正确。

    关于chef-infra - 为什么 Chef 不能解决我的 Recipe ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26392727/

    相关文章:

    chef-infra - 如何使 Chef 与特定用户一起执行并加载其环境值

    amazon-web-services - Chef : HOME environment variable (or HOMEDRIVE and HOMEPATH) must be set and point to a directory

    chef-infra - 如何使用 Berkshelf 管理组织 repo ?

    amazon-web-services - 将 Cloudformation 与 Chef 服务器结合使用

    redis - 如何使用 Chef JSON 设置 redis 和 sidekiq 配置

    windows - Windows 上的 Test-Kitchen serverspec 测试异常

    ruby - Chef 模板问题,过时的变量

    chef-infra - 运行 Chef 客户端时无法从 Recipe 中找到菜谱

    ubuntu - 某环境下的 Knife 列表内核版本

    chef-infra - 创建客户端时出现vagrant up错误? Chef-stacktrace:OpenSSL::PKey::RSAError:需要私钥