缓存不同步,无法对包文件进行x-ref

时间:2017-05-17 18:04:21

标签: chef apt-get

在Amazon EC2实例上通过CHEF安装软件包时出现以下错误:

Cache is out of sync, can't x-ref a package file

以下几行:

%w{htop sysstat bwm-ng needrestart debian-goodies}.each do |pkg|
  package pkg
end

我做了很多谷歌搜索,但没有答案,我现在知道这意味着什么,更重要的是如何防止它:(

================================================================================
Error executing action `install` on resource 'apt_package[htop]'
================================================================================

Mixlib::ShellOut::ShellCommandFailed
------------------------------------
Expected process to exit with [0], but received '100'
---- Begin output of apt-cache policy htop ----
STDOUT: htop:
Installed: 2.0.1-1ubuntu1
Candidate: 2.0.1-1ubuntu1
Version table:
*** 2.0.1-1ubuntu1 500
500 http://eu-central-1.ec2.archive.ubuntu.com/ubuntu xenial-updates/universe amd64 Packages
STDERR: E: Cache is out of sync, can't x-ref a package file
---- End output of apt-cache policy htop ----
Ran apt-cache policy htop returned 100

Resource Declaration:
---------------------
# In /var/chef/runs/0c236d60-212c-4e9a-a6c1-fb8af8960425/local-mode-cache/cache/cookbooks/k2go-common/recipes/setup.rb

20:   package pkg
21: end

Compiled Resource:
------------------
# Declared in /var/chef/runs/0c236d60-212c-4e9a-a6c1-fb8af8960425/local-mode-cache/cache/cookbooks/k2go-common/recipes/setup.rb:20:in `block in from_file'

apt_package("htop") do
package_name "htop"
action [:install]
retries 0
retry_delay 2
default_guard_interpreter :default
declared_type :package
cookbook_name "k2go-common"
recipe_name "setup"
end

Platform:
---------
x86_64-linux

[2017-05-17T19:01:36+02:00] INFO: Running queued delayed notifications before re-raising exception
[2017-05-17T19:01:36+02:00] ERROR: Running exception handlers
[2017-05-17T19:01:36+02:00] ERROR: Exception handlers complete
[2017-05-17T19:01:36+02:00] FATAL: Stacktrace dumped to /var/chef/runs/0c236d60-212c-4e9a-a6c1-fb8af8960425/local-mode-cache/cache/chef-stacktrace.out
[2017-05-17T19:01:36+02:00] FATAL: Please provide the contents of the stacktrace.out file if you file a bug report
[2017-05-17T19:01:36+02:00] ERROR: apt_package[htop] (k2go-common::setup line 20) had an error: Mixlib::ShellOut::ShellCommandFailed: Expected process to exit with [0], but received '100'
---- Begin output of apt-cache policy htop ----
STDOUT: htop:
Installed: 2.0.1-1ubuntu1
Candidate: 2.0.1-1ubuntu1
Version table:
*** 2.0.1-1ubuntu1 500
500 http://eu-central-1.ec2.archive.ubuntu.com/ubuntu xenial-updates/universe amd64 Packages
STDERR: E: Cache is out of sync, can't x-ref a package file
---- End output of apt-cache policy htop ----
Ran apt-cache policy htop returned 100
[2017-05-17T19:01:36+02:00] FATAL: Chef::Exceptions::ChildConvergeError: Chef run process exited unsuccessfully (exit code 1)

我在日志中看到http://eu-central-1.ec2.archive.ubuntu.com/ubuntu返回了500个状态代码,因此Ubuntu可能会出现某种(短暂的)中断?我相信我们可以添加/增加重试次数,默认为0?

2 个答案:

答案 0 :(得分:2)

是的,它看起来是在ubuntu来源暂时中断,因此增加重试选项将使资源能够捕获异常并再次重试,即

%w{htop sysstat bwm-ng needrestart debian-goodies}.each do |pkg|
  package pkg do
    retries 5
  end
end

但是在安装软件包之前在ubuntu上运行apt-get update总是好的,因为它实际上会从Internet源检索有关可以安装哪些软件包的信息,包括当前安装的软件包的可用更新。

为此你可以看看:

https://docs.chef.io/resource_apt_update.html

https://supermarket.chef.io/cookbooks/apt

答案 1 :(得分:1)

您可能需要apt-get update,您可以使用apt_update资源。