厨师为什么不能解析我的菜谱? [英] Why can't chef resolve my cookbooks?
问题描述
简介
我正在学习Chef在工作中自动进行服务器管理。
我从此处
下载了Chefdk 3.0,现在我正在尝试构建我的第一本使用厨师的食谱。
Intro I am learning Chef to automate the server management at work. I downloaded chefdk 3.0 from here and now I am trying to build my first cookbook using chef.
重要
我正在Windows环境中使用它进行测试,我希望它能够失败,因为Windows没有iptables,但我不希望它失败,因为它找不到菜谱。我尝试使用 Windows食谱,它可以正常工作。
Important I am using this in a Windows environment for testing purpose, I do expect it to fail since Windows does not have iptables, but I do not expect it to fail saying that it can't find the cookbook. I've tried using Windows cookbook and it works.
问题
我可以创建菜谱并运行它,但是我无法引用超市中的依赖项。
The problem I am able to create the cookbook and run it, but I am not able to reference dependencies from supermarket.
我尝试了两种选择:
替代1
我使用了以下命令创建菜谱
I used the following command to create the cookbook
chef generate cookbook learn_chef_httpd
(来自本教程)
我能够完成本教程,现在我想测试引用另一本食谱,因此我选择了 simple_iptables
I was able to complete the tutorial and now I would like to test referencing another cookbook, so I chose simple_iptables
我添加了这一行
cookbook 'simple_iptables', '~> 0.7.0'
到我的Berksfile,如超市中所述。
To my Berksfile, as described in the Supermarket.
然后将这些行添加到我的default.rb文件中:
Then I added these lines to my default.rb file:
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
I中配置依赖项尝试将其添加到元数据中:
I tried adding it to the metadata:
depends 'simple_iptables', '~> 0.7.0'
但我仍然收到错误:
Error Resolving Cookbooks for Run List:
Missing Cookbooks:
No such cookbook: simple_iptables
替代2
我仍在尝试它可以正常工作,因此我也尝试使其成为 berkshelf方式,因此我创建了新的食谱。
I am still trying to make it work so I also tried making it "the berkshelf way", so I created a new cookbook.
berks cookbook test
我添加了这一行
cookbook 'simple_iptables', '~> 0.7.0'
到我的Berksfile,如超市中所述。
To my Berksfile, as described in the Supermarket.
然后将这些行添加到我的default.rb文件中:
Then I added these lines to my default.rb file:
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安装:
Executed berks install:
批量安装
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
I中配置依赖项尝试将其添加到元数据中:
I tried adding it to the metadata:
depends 'simple_iptables', '~> 0.7.0'
但我仍然收到错误:
Error Resolving Cookbooks for Run List:
Missing Cookbooks:
No such cookbook: simple_iptables
我看着〜/ berkshelf文件夹,里面有食谱。
I looked at the ~/berkshelf folder and the cookbooks are there.
* *替代3 **
** Alternative 3 **
我在亚马逊上启动了一个CentOS 6.5 EC2实例,安装了Ruby 2.1.3和Chef。
创建了〜/ chef-repo / cookbooks文件夹
I started a CentOS 6.5 EC2 instance on Amazon, installed Ruby 2.1.3 and Chef. created a ~/chef-repo/cookbooks folder
我使用berkshelf创建了食谱,运行
I created a cookbook using berkshelf, ran
bundle install
添加了引用/代码,如其他备用
然后
added the reference/code as in the other alterantives then
berks install
并以与上次相同的方式运行。
and ran the same way I did last time.
我遇到了同样的问题。
我想念什么?我需要什么使其工作?
What am I missing? What do I need to make it work?
推荐答案
请确保已配置 chef_repo_path
,如文档中所述。
Make sure you have configured your chef_repo_path
as described in the docs.
基本上本地模式
需要知道在哪里可以找到您的菜谱,角色,环境,数据包等。遗憾的是,关于在何处/如何设置 chef_repo_path
Basically local-mode
needs to know where to find your cookbooks, roles, environments, data bags, etc. Sadly, the documentation is not super clear on where/how you set chef_repo_path
的信息尚不清楚。代码。
Here's what I can tell from the code.
- 如果找到
client.rb
并包含cookbook_path
,chef_repo_path
=#{cookbook_path} / ..
- 如果找到
knife.rb
并包含cookbook_path
,Chef_repo_path =#{cookbook_path} / ..
- 厨师可以尝试确定路径。 代码将从
pwd
向上查找名为cookbooks
的目录。如果找到它,则会将cookbooks /..
设置为您的Chef_repo_path。 - 如果其他所有操作均失败,则
pwd
将用作您的chef_repo_path
- if
client.rb
is found and containscookbook_path
,chef_repo_path
="#{cookbook_path}/.."
- if
knife.rb
is found and containscookbook_path
,chef_repo_path = "#{cookbook_path}/.."
- Chef can try to divine the path. The code will search from
pwd
upward looking for a directory calledcookbooks
. If it finds it, thencookbooks/..
will be set as your chef_repo_path. - If all else fails,
pwd
will be used as yourchef_repo_path
如果您使用的是Berkshelf,最好的办法是做一个 Berks供应商
,以便获得一个目录,该目录将包含您需要的所有菜谱。然后,您可以将Chef_repo_path指向烹饪书
目录的父目录,该目录保存您供应的烹饪书。
If you are using Berkshelf, your best bet is to do a berks vendor
in order to get a single directory will ALL of the cookbooks you need. You can then point chef_repo_path to the parent of the cookbooks
directory which holds your vendored cookbooks.
请记住,从10分钟的源代码挖掘中,所以我可能不太正确。
Mind you, that's from 10 minutes of digging in the source code, so I may not have it quite right.
这篇关于厨师为什么不能解析我的菜谱?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!