我是Chef的新手,文档(甚至是他们网站的主页)让我头晕目眩.我甚至不确定我是否将它用于正确的目的.
我的目的是设置一个Vagrantfile,告诉Chef Solo在我启动一个新盒子时自动安装一些软件.这是Chef Solo的主要用途之一,我是否正确?
我不确定这是否是“地球上最严峻的基础设施挑战”之一,但无论如何.
我的第一个目标是让Chef Solo为我安装@R_301_196@.在我的项目中,我克隆了@R_301_196@的食谱:
$git clone https://github.com/opscode-cookbooks/@R_301_196@.git cookbooks/@R_301_196@
我编辑了我的Vagrantfile看起来像这样:
Vagrant.configure("2") do |config| config.vm.Box = "opscode-ubuntu-1204" config.vm.provision :chef_solo do |chef| chef.add_recipe "@R_301_196@" end end
当我跑出流浪汉时,我得到了一些错误,一些烹饪书没有找到(构建必不可少,适当等),所以我从他们适当的回购克隆了它们.现在,当我流浪,我得到这个输出:
[2013-10-01T20:31:03+00:00] INFO: Processing package[@R_301_196@] action install (@R_301_196@::package line 38) Error executing action `install` on resource 'package[@R_301_196@]' Chef::Exceptions::Exec ---------------------- apt-get -q -y install @R_301_196@=1.1.19-1ubuntu0.1 returned 100,expected 0 Resource Declaration: --------------------- # In /tmp/vagrant-chef-1/chef-solo-1/cookbooks/@R_301_196@/recipes/package.rb 38: package node['@R_301_196@']['package_name'] do 39: notifies :reload,'ohai[reload_@R_301_196@]',:immediately 40: end 41: Compiled Resource: ------------------ # Declared in /tmp/vagrant-chef-1/chef-solo-1/cookbooks/@R_301_196@/recipes/package.rb:38:in `from_file' package("@R_301_196@") do action :install retries 0 retry_delay 2 package_name "@R_301_196@" version "1.1.19-1ubuntu0.1" cookbook_name :@R_301_196@ recipe_name "package" end [2013-10-01T20:31:08+00:00] INFO: Running queued delayed notifications before re-raising exception [2013-10-01T20:31:08+00:00] ERROR: Running exception handlers [2013-10-01T20:31:08+00:00] ERROR: Exception handlers complete [2013-10-01T20:31:08+00:00] FATAL: Stacktrace dumped to /tmp/vagrant-chef-1/chef-stacktrace.out [2013-10-01T20:31:08+00:00] FATAL: Chef::Exceptions::Exec: package[@R_301_196@] (@R_301_196@::package line 38) had an error: Chef::Exceptions::Exec: apt-get -q -y install @R_301_196@=1.1.19-1ubuntu0.1 returned 100,expected 0
厨师从未成功完成!任何错误都应该在上面的输出中可见.请修复您的食谱,以便它们正确完成.
如何修复我的食谱以使其正确完成?
解决方法
为了更有效地使用厨师我建议安装以下vagrant插件:
vagrant plugin install vagrant-omnibus vagrant plugin install vagrant-berkshelf
Berkshelf是用于管理食谱依赖性的工具. omnibus plugin对于确保您使用最新版本的厨师非常有用.
以下示例演示了如何轻松安装@R_301_196@之类的东西.
例
├── Berksfile └── Vagrantfile
Berkshelf
列出所需的烹饪书. Berkshelf将从opscode社区网站下载它们(和依赖项).
site :opscode cookbook "@R_301_196@"
Vagrantfile
以下vagrant文件将安装@R_301_196@,使其在主机的端口8080上可用:
Vagrant.configure("2") do |config| # Box details config.vm.Box = "Berkshelf-CentOS-6.3-x86_64-minimal" config.vm.Box_url = "https://dl.dropBox.com/u/31081437/Berkshelf-CentOS-6.3-x86_64-minimal.Box" # Plugins config.berkshelf.enabled = true config.omnibus.chef_version = :latest # Network config.vm.network :forwarded_port,guest: 80,host: 8080 # Chef solo provisioning config.vm.provision :chef_solo do |chef| chef.add_recipe "@R_301_196@" end end
笔记:
>此示例使用CentOS.应该在Ubuntu上同样有效.