缓存不同步,无法外部引用包文件

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

在 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 可能有某种(短暂的)中断?我相信我们可以 add/increase 重试,默认情况下为 0?

您可能需要一个 apt-get update,您可以使用 apt_update 资源来完成。

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

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

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

为此你可以看看使用:

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

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