SyntaxHighlighter JS


Packer and package installs

When using Packer to generate an Ubuntu AWS AMI, I use a shell script provisioner to install and update packages via apt-get. When executing apt commands in the script, I was getting the errors such as: 
"Package has no installation candidate"
"Unable to locate package" 

The error in the shell script was that I was executing apt-get commands before the AWS cloud-init completed.

To check that cloud-init finished before running apt-get, modify the script via

while [ ! -f  /var/lib/cloud/instance/boot-finished ];
    echo "Waiting for cloud-init to finish ..."
    sleep 2

apt-get update -y
apt-get install -y package