通过Vagrant + Chef安装多个软件包

时间:2011-03-17 13:30:40

标签: chef cookbook vagrant

我刚刚发现了Vagrant + Chef,我正在尝试创建一个简单的方法来在节点上安装多个包。我认为这样的东西可以起作用(我完全是新的红宝石):

# (From cookbooks/MY_COOCKBOOK/recipes/default.rb)
# Install required packages
%w{build-essential libncurses5-dev openssl libssl-dev}.each do |pkg|
  package pkg do
    action :install
  end
end

但是这失败并出现以下错误:

[default] [Thu, 17 Mar 2011 06:24:27 -0700] INFO: Installing package[libssl-dev] version 0.9.8k-7ubuntu8.5
: stdout
[default] /usr/lib/ruby/gems/1.8/gems/chef-0.9.12/bin/../lib/chef/mixin/command.rb:184:in `handle_command_failures': stderr
[default] : : stderr
[default] apt-get -q -y install libssl-dev=0.9.8k-7ubuntu8.5 returned 100, expected 0: stderr
[default]  (: stderr
[default] Chef::Exceptions::Exec: stderr
[default] )
: stderr
[default]   from /usr/lib/ruby/gems/1.8/gems/chef-0.9.12/bin/../lib/chef/mixin/command.rb:131:in `run_command'
    from /usr/lib/ruby/gems/1.8/gems/chef-0.9.12/bin/../lib/chef/mixin/command.rb:199:in `run_command_with_systems_locale'
    from /usr/lib/ruby/gems/1.8/gems/chef-0.9.12/bin/../lib/chef/provider/package/apt.rb:68:in `install_package'
    from /usr/lib/ruby/gems/1.8/gems/chef-0.9.12/bin/../lib/chef/provider/package.rb:60:in `action_install'
[...]

: stderr
[default] [Thu, 17 Mar 2011 06:24:34 -0700] ERROR: package[libssl-dev] (/tmp/vagrant-chef/cookbooks-0/erlang-src/recipes/default.rb:22:in `from_file') had an error:
apt-get -q -y install libssl-dev=0.9.8k-7ubuntu8.5 returned 100, expected 0
/usr/lib/ruby/gems/1.8/gems/chef-0.9.12/bin/../lib/chef/mixin/command.rb:184:in `handle_command_failures'
/usr/lib/ruby/gems/1.8/gems/chef-0.9.12/bin/../lib/chef/mixin/command.rb:131:in `run_command'
/usr/lib/ruby/gems/1.8/gems/chef-0.9.12/bin/../lib/chef/mixin/command.rb:199:in `run_command_with_systems_locale'
/usr/lib/ruby/gems/1.8/gems/chef-0.9.12/bin/../lib/chef/provider/package/apt.rb:68:in `install_package'
/usr/lib/ruby/gems/1.8/gems/chef-0.9.12/bin/../lib/chef/provider/package.rb:60:in `action_install'

我的印象是我错过了一些基本的东西......

2 个答案:

答案 0 :(得分:17)

事实证明,我只是错过了我的Vagrantfile上的“apt”配方,它在安装所需的包之前运行apt-get更新。所以,以上是正确的。

答案 1 :(得分:4)

只需在此处添加此答案以供将来参考。如果您遇到必须在调用某些apt-get update命令之前运行package的情况,则可以使用此代码段:

execute "update package index" do
  command "apt-get update"
  ignore_failure true
  action :nothing
end.run_action(:run)

它运作正常。