![Chef Opscode apt cookbook-apt-get install 返回 100,预期 0](https://linux22.com/image/799522/Chef%20Opscode%20apt%20cookbook-apt-get%20install%20%E8%BF%94%E5%9B%9E%20100%EF%BC%8C%E9%A2%84%E6%9C%9F%200.png)
我在安装了 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)在任何 cookbook 之前的运行列表中。这样,一些缓存问题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
您能给我一些线索让我可以继续我的调查吗?
非常感谢!
答案1
可能和权限不足有关:
$ 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