【发布时间】:2014-12-11 03:08:36
【问题描述】:
简介 我正在学习 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 没有找到食谱
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 way”,所以我创建了一本新的食谱。
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 安装
然后运行它:
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
并以与上次相同的方式运行。
我遇到了同样的问题。
我错过了什么?我需要什么才能让它发挥作用?
【问题讨论】:
-
您是将“这些行”添加到您的 berksfile 还是您的 default.rb 配方?
-
到 default.rb 配方
-
我可能是错的,但你没有提到在修改 berksfile 后做一个
berks install。您可能还希望使用 berks vendor 创建一个包含所有需要的说明书的目录,并将 chef-client repo 路径指向该目录。总而言之,你的食谱在你的磁盘上,但不是零厨师看的地方。 -
@Tensibai 你是对的,我没有提到它,对不起,我的错!我更新了问题
标签: chef-infra chef-recipe berkshelf