J'essaie de créer une AMI basée sur AMI-3b054701
dans la région ap-southeast-2
. La configuration de Packer a un approvisionnement simple:
#!/bin/bash -e
info() {
echo -e "[INFO] $1\n"
}
exec_cmd() {
echo -e "\n[INFO] $1\n"
eval $1
}
exec_cmd "apt-get update"
exec_cmd "apt-get -y upgrade"
exec_cmd "apt-get -y install build-essential git Zip unzip wget default-jre"
Cela fonctionne parfois sans problème mais échoue parfois avec cette erreur:
AMI: [INFO] apt-get -y install build-essential git Zip unzip wget default-jre
AMI:
AMI: Reading package lists... Done
AMI: Building dependency tree
AMI: Reading state information... Done
AMI: Package build-essential is not available, but is referred to by another package.
AMI: This may mean that the package is missing, has been obsoleted, or
AMI: is only available from another source
AMI:
AMI: Package default-jre is not available, but is referred to by another package.
AMI: This may mean that the package is missing, has been obsoleted, or
AMI: is only available from another source
AMI:
AMI: Package Zip is not available, but is referred to by another package.
AMI: This may mean that the package is missing, has been obsoleted, or
AMI: is only available from another source
AMI:
AMI: E: Package 'build-essential' has no installation candidate
AMI: E: Package 'Zip' has no installation candidate
AMI: E: Package 'default-jre' has no installation candidate
J'ai perdu une journée entière à trouver un moyen d'éviter cela. Il y a un suggéré solution sur Stack Exchange mais c'est plus un bidouillage qu'une solution. Existe-t-il un moyen d'empêcher cette erreur de se produire par intermittence?
Voici la sortie complète de Packer
==> AMI: Prevalidating AMI Name...
==> AMI: Inspecting the source AMI...
==> AMI: Creating temporary keypair: packer 55d33324-e319-bd49-24c5-c06a18b4fe09
==> AMI: Launching a source AWS instance...
AMI: Instance ID: i-8b78cd55
==> AMI: Waiting for instance (i-8b78cd55) to become ready...
==> AMI: Waiting for SSH to become available...
==> AMI: Connected to SSH!
==> AMI: Provisioning with Shell script: scripts/provision.sh
AMI:
AMI: [INFO] apt-get update
AMI:
AMI: Ign http://security.ubuntu.com trusty-security InRelease
AMI: Ign http://archive.ubuntu.com trusty InRelease
AMI: Get:1 http://security.ubuntu.com trusty-security Release.gpg [933 B]
AMI: Ign http://archive.ubuntu.com trusty-updates InRelease
AMI: Get:2 http://security.ubuntu.com trusty-security Release [63.5 kB]
AMI: Hit http://archive.ubuntu.com trusty Release.gpg
AMI: Get:3 http://archive.ubuntu.com trusty-updates Release.gpg [933 B]
AMI: Hit http://archive.ubuntu.com trusty Release
AMI: Get:4 http://archive.ubuntu.com trusty-updates Release [63.5 kB]
AMI: Get:5 http://security.ubuntu.com trusty-security/main AMD64 Packages [333 kB]
AMI: Get:6 http://security.ubuntu.com trusty-security/restricted AMD64 Packages [8875 B]
AMI: Hit http://archive.ubuntu.com trusty/main AMD64 Packages
AMI: Get:7 http://security.ubuntu.com trusty-security/universe AMD64 Packages [114 kB]
AMI: Hit http://archive.ubuntu.com trusty/restricted AMD64 Packages
AMI: Hit http://archive.ubuntu.com trusty/universe AMD64 Packages
AMI: Get:8 http://security.ubuntu.com trusty-security/multiverse AMD64 Packages [3686 B]
AMI: Hit http://archive.ubuntu.com trusty/multiverse AMD64 Packages
AMI: Get:9 http://security.ubuntu.com trusty-security/main Translation-en [181 kB]
AMI: Hit http://archive.ubuntu.com trusty/main Translation-en
AMI: Hit http://security.ubuntu.com trusty-security/multiverse Translation-en
AMI: Hit http://archive.ubuntu.com trusty/multiverse Translation-en
AMI: Hit http://security.ubuntu.com trusty-security/restricted Translation-en
AMI: Hit http://archive.ubuntu.com trusty/restricted Translation-en
AMI: Get:10 http://security.ubuntu.com trusty-security/universe Translation-en [66.6 kB]
AMI: Hit http://archive.ubuntu.com trusty/universe Translation-en
AMI: Get:11 http://archive.ubuntu.com trusty-updates/main AMD64 Packages [605 kB]
AMI: Get:12 http://archive.ubuntu.com trusty-updates/restricted AMD64 Packages [15.3 kB]
AMI: Get:13 http://archive.ubuntu.com trusty-updates/universe AMD64 Packages [308 kB]
AMI: Get:14 http://archive.ubuntu.com trusty-updates/multiverse AMD64 Packages [11.9 kB]
AMI: Get:15 http://archive.ubuntu.com trusty-updates/main Translation-en [292 kB]
AMI: Hit http://archive.ubuntu.com trusty-updates/multiverse Translation-en
AMI: Hit http://archive.ubuntu.com trusty-updates/restricted Translation-en
AMI: Get:16 http://archive.ubuntu.com trusty-updates/universe Translation-en [163 kB]
AMI: Fetched 2232 kB in 16s (134 kB/s)
AMI: Reading package lists... Done
AMI:
AMI: [INFO] apt-get -y upgrade
AMI:
AMI: Reading package lists... Done
AMI: Building dependency tree
AMI: Reading state information... Done
AMI: Calculating upgrade... Done
AMI: The following packages have been kept back:
AMI: linux-headers-generic linux-headers-virtual linux-image-virtual
AMI: linux-virtual
AMI: 0 upgraded, 0 newly installed, 0 to remove and 4 not upgraded.
AMI:
AMI: [INFO] apt-get -y install build-essential git Zip unzip wget default-jre
AMI:
AMI: Reading package lists... Done
AMI: Building dependency tree
AMI: Reading state information... Done
AMI: Package build-essential is not available, but is referred to by another package.
AMI: This may mean that the package is missing, has been obsoleted, or
AMI: is only available from another source
AMI:
AMI: Package default-jre is not available, but is referred to by another package.
AMI: This may mean that the package is missing, has been obsoleted, or
AMI: is only available from another source
AMI:
AMI: Package Zip is not available, but is referred to by another package.
AMI: This may mean that the package is missing, has been obsoleted, or
AMI: is only available from another source
AMI:
AMI: E: Package 'build-essential' has no installation candidate
AMI: E: Package 'Zip' has no installation candidate
AMI: E: Package 'default-jre' has no installation candidate
==> AMI: Terminating the source AWS instance...
==> AMI: No AMIs to cleanup
Très probablement, vous avez rencontré une situation critique avec cloud-init. Ce problème de packer donne quelques idées, et j’ai essayé avec succès la suggestion suivante donnée par le PO:
echo "waiting 180 seconds for cloud-init to update /etc/apt/sources.list"
timeout 180 /bin/bash -c \
'until stat /var/lib/cloud/instance/boot-finished 2>/dev/null; do echo waiting ...; sleep 1; done'
Cela semble toujours être un problème. Je l'ai résolu en créant une copie de l'image stock Ubuntu et en y mettant un wrapper apt-get qui attend que les installations existantes se terminent avant de continuer (au lieu d'échouer).
apt-get
(voir ci-dessous) dans /usr/local/sbin/apt-get
Sudo chmod 755 /usr/local/sbin/apt-get
/usr/local/sbin/
est au début de la variable PATH dans /etc/environment
.Script adapté de cela
#!/bin/bash
#
# Wait for the package manager locks to be released before trying to call apt-get
#
i=0
tput sc
while fuser /var/lib/dpkg/lock >/dev/null 2>&1 || fuser /var/lib/apt/lists/lock >/dev/null 2>&1; do
case $(($i % 4)) in
0 ) j="-" ;;
1 ) j="\\" ;;
2 ) j="|" ;;
3 ) j="/" ;;
esac
tput rc
echo -en "\r[$j] Waiting for other software managers to finish..."
sleep 0.5
((i=i+1))
done
/usr/bin/apt-get "$@"
J'ai demandé à l'équipe de serveurs de jeter un coup d'œil à cela et, pendant qu'ils préparaient une réponse, je peux dire que la solution sur StackExchange concerne les problèmes de "déséquilibre de somme de hachage" qui n'apparaissent pas dans votre sortie.
Pour une raison quelconque, les métadonnées de l’archive ne semblent pas correspondre aux paquets que vous demandez d’installer (qui sont en général), mais apt sait que d’autres paquets en dépendent, alors il vous dit que le fait de ne pas le faire pense que tu es fou non plus. ;-)