Apt

Chef Opscode apt cookbook - apt-get install 返回 100,預期為 0

  • February 25, 2013

我在安裝了 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 上執行該命令效果很好。

在調查了一段時間後,我發現人們建議在執行列表中執行Opscodeapt食譜(版本 1.9.0),然後再執行任何食譜。這樣,apt-get update記憶體的一些問題就解決了。

所以我先把食譜放在我的執行列表中apt,但我仍然遇到同樣的錯誤:

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

引用自:https://serverfault.com/questions/482143