Update robot template to download Ansible roles
[releng/builder.git] / packer / provision / baseline.sh
index c1ce0bbaeab85be7b614808827a8626c5e1a1806..aae30d44b1e3be34881adf56e5646a8ef1fedde7 100644 (file)
@@ -7,6 +7,8 @@ set -xeu -o pipefail
 
 enable_service() {
     # Enable services for Ubuntu instances
+    # We purposely want to allow globbing to build the package array
+    # shellcheck disable=SC2206
     services=($@)
 
     for service in "${services[@]}"; do
@@ -72,6 +74,8 @@ ensure_ubuntu_install() {
     # On Ubuntu sometimes the mirrors fail to install a package. This wrapper
     # checks that a package is successfully installed before moving on.
 
+    # We purposely want to allow globbing to build the package array
+    # shellcheck disable=SC2206
     packages=($@)
 
     for pkg in "${packages[@]}"
@@ -79,6 +83,10 @@ ensure_ubuntu_install() {
         # Retry installing package 5 times if necessary
         for i in {0..5}
         do
+
+            # Wait for any background apt processes to finish before running apt
+            while pgrep apt > /dev/null; do sleep 1; done
+
             echo "$i: Installing $pkg"
             if [ "$(dpkg-query -W -f='${Status}' "$pkg" 2>/dev/null | grep -c "ok installed")" -eq 0 ]; then
                 apt-cache policy "$pkg"
@@ -277,9 +285,6 @@ Dpkg::Options {
 
 EOF
 
-    # Add hostname to /etc/hosts to fix 'unable to resolve host' issue with sudo
-    sed -i "/127.0.0.1/s/$/ $(hostname)/" /etc/hosts
-
     echo "---> Updating operating system"
 
     # add additional repositories