Intro我正在学习 Chef 以自动化工作中的服务器管理。
我从下载了 Chefdk 3.0here https://downloads.getchef.com/chef-dk/windows/#/现在我正在尝试使用厨师制作我的第一本食谱。
重要的我在 Windows 环境中使用它进行测试,我确实希望它会失败,因为 Windows 没有 iptables,但我不希望它会失败,说它找不到食谱。我尝试过使用Windows食谱 https://supermarket.getchef.com/cookbooks/windows它有效。
问题我能够创建食谱并运行它,但我无法引用超市的依赖项。
我尝试了两种选择:
替代方案1
我使用以下命令来创建食谱
chef generate cookbook learn_chef_httpd
(from 本教程 https://learn.getchef.com/rhel/make-your-recipe-more-manageable/)
我能够完成本教程,现在我想测试引用另一本食谱,所以我选择简单的iptables https://api.berkshelf.com/cookbooks/simple_iptables/versions/0.7.0
我添加了这一行
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
我仍在努力让它发挥作用,所以我也尝试让它成为“伯克谢尔夫方式”,所以我创建了一本新的食谱。
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安装:
伯克斯安装
并运行它:
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
和我上次一样跑。
我也遇到了同样的问题。
我缺少什么?我需要什么才能让它发挥作用?