厨师的Opscode apt cookbook – apt-get install返回100,预计为0

我在安装了Ubuntu 12的干净VPS上运行Chef solo(版本11.4.0),并且遇到了一些apt问题。 问题是任何package命令都会引发一个错误:

 Chef::Exceptions::Exec ---------------------- apt-get -q -y install update-notifier-common=0.126 returned 100, expected 0 

但是,在shell上运行这个命令是完美的。

经过一番调查,我发现人们推荐在任何食谱之前在运行列表中运行Opscode apt Cookbook (版本1.9.0)。 这样,解决了apt-get update cache的一些问题。

所以我先把我的食谱放到我的菜单里,而且我还是有同样的错误:

 Recipe: apt::default * execute[apt-get-update] action run - execute apt-get update * execute[apt-get update] action nothing (up to date) * execute[apt-get autoremove] action nothing (up to date) * execute[apt-get autoclean] action nothing (up to date) * package[update-notifier-common] action install ================================================================================ Error executing action `install` on resource 'package[update-notifier-common]' ================================================================================ Chef::Exceptions::Exec ---------------------- apt-get -q -y install update-notifier-common=0.126 returned 100, expected 0 Resource Declaration: --------------------- # In /home/ubuntu/.chef/toldo-cookbooks/cookbooks/apt/recipes/default.rb 48: package "update-notifier-common" do 49: notifies :run, resources(:execute => "apt-get-update"), :immediately 50: end 51: Compiled Resource: ------------------ # Declared in /home/ubuntu/.chef/toldo-cookbooks/cookbooks/apt/recipes/default.rb:48:in `from_file' package("update-notifier-common") do action :install retries 0 retry_delay 2 package_name "update-notifier-common" version "0.126" cookbook_name :apt recipe_name "default" end [2013-02-24T19:31:10+00:00] ERROR: Running exception handlers [2013-02-24T19:31:10+00:00] ERROR: Exception handlers complete Chef Client failed. 1 resources updated [2013-02-24T19:31:10+00:00] FATAL: Stacktrace dumped to /home/ubuntu/.chef/toldo-cookbooks/chef-stacktrace.out [2013-02-24T19:31:10+00:00] FATAL: Chef::Exceptions::Exec: package[update-notifier-common] (apt::default line 48) had an error: Chef::Exceptions::Exec: apt-get -q -y install update-notifier-common=0.126 returned 100, expected 0 

你有什么线索可以继续我的调查吗?

非常感谢!

这可能与缺乏特权有关:

 $ id uid=1000(gaizka) $ apt-get install vim # Just kidding! E: Could not open lock file /var/lib/dpkg/lock - open (13: Permission denied) E: Unable to lock the administration directory (/var/lib/dpkg/), are you root? $ echo $? 100 

当我和厨师一起玩时,我用这个:

 # Usage: # Chef::Provider::Package::Apt.send(:include, CustomApt::UseSudo) module CustomApt module UseSudo def self.included(base) base.class_eval do alias_method :install_package_without_sudo, :install_package def install_package(name, version) package_name = "#{name}=#{version}" package_name = name if @is_virtual_package run_command_with_systems_locale( :command => "sudo apt-get -q -y#{expand_options(@new_resource.options)} install #{package_name}", :environment => { "DEBIAN_FRONTEND" => "noninteractive" } ) end end end end end 

我将其包含在我的食谱中,即install_packages.rb

 # So we install packages with sudo Chef::Provider::Package::Apt.send(:include, CustomApt::UseSudo) include_recipe "imagemagick::devel" node['application']['install_packages'].each do |package_name| package package_name do action :install end end