官方 Ubuntu AWS AMI 上的“apt-get update”行为不一致

Mys*_*tic 5 ubuntu amazon-ami amazon-web-services apt packer

apt我在官方 Ubuntu 映像 ( ) 上遇到各种不一致的错误ami-83e769fb。我使用 Packer 构建 AMI,大约 40% 的情况下会失败。重新运行脚本成功。

我的脚本运行:

sudo apt-get clean all
sudo apt-get update
Run Code Online (Sandbox Code Playgroud)

在安装任何软件包之前。

有时我会收到此错误:

amazon-ebs: W: GPG error: http://archive.ubuntu.com/ubuntu artful InRelease: Splitting up /var/lib/apt/lists/archive.ubuntu.com_ubuntu_dists_artful_InRelease into data and signature failed
amazon-ebs: E: The repository 'http://archive.ubuntu.com/ubuntu artful InRelease' is not signed.
Run Code Online (Sandbox Code Playgroud)

有时apt-get update会击中http://us-west-2.ec2.archive.ubuntu.com/ubuntu……有时却不会。

其他时候软件包丢失(如apache2python3)。

我不明白为什么这种行为不一致。

如何让apt-get update官方 Ubuntu AMI 持续工作?

小智 6

如果您正在使用,cloud-init则可以等待它完成。

while [ ! -f /var/lib/cloud/instance/boot-finished ]; do
   echo 'Waiting for cloud-init...'
   sleep 1
done
Run Code Online (Sandbox Code Playgroud)

例如打包器json:

{
  "type": "shell",
  "inline": [
    "while [ ! -f /var/lib/cloud/instance/boot-finished ]; do echo 'Waiting for cloud-init...'; sleep 1; done"
  ]
}
Run Code Online (Sandbox Code Playgroud)

参考:


ctr*_*oot 1

我自己刚刚遇到了这个问题,我相信这是因为 cloud-init 在运行时仍在配置 EC2 实例的过程中apt-get。我通过在实例启动后立即运行的脚本中插入 30 秒的延迟来解决这个问题。我认为更好的方法是要求 cloud-init 运行任何脚本User Data,甚至让它为您处理包安装和更新 [1]。对于我的用例,我不想承认 cloud-init,添加延迟是一个可以接受的解决方案。

  1. https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/user-data.html