Skip to content

Commit e702234

Browse files
committed
chore: retry on fail for initial installs
1 parent f5ac9c0 commit e702234

File tree

1 file changed

+27
-12
lines changed

1 file changed

+27
-12
lines changed

ebssurrogate/scripts/surrogate-bootstrap-nix.sh

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,18 +29,33 @@ function waitfor_boot_finished {
2929
}
3030

3131
function install_packages {
32-
# Setup Ansible on host VM
33-
apt-get update && sudo apt-get install software-properties-common -y
34-
add-apt-repository --yes --update ppa:ansible/ansible && sudo apt-get install ansible -y
35-
ansible-galaxy collection install community.general
36-
37-
# Update apt and install required packages
38-
apt-get update
39-
apt-get install -y \
40-
gdisk \
41-
e2fsprogs \
42-
debootstrap \
43-
nvme-cli
32+
trap 'echo "Error on line $LINENO"' ERR
33+
34+
retry() {
35+
local retries=3
36+
local count=1
37+
until "$@"; do
38+
[[ $count -eq $retries ]] && return 1
39+
echo "Command failed, attempt $count/$retries"
40+
((count++))
41+
sleep 10
42+
done
43+
return 0
44+
}
45+
46+
retry apt-get update
47+
retry apt-get install -y software-properties-common
48+
retry add-apt-repository --yes --update ppa:ansible/ansible
49+
50+
retry apt-get install -y ansible
51+
if ! command -v ansible &>/dev/null; then
52+
echo "Ansible installation failed"
53+
return 1
54+
fi
55+
56+
retry ansible-galaxy collection install community.general
57+
retry apt-get update
58+
retry apt-get install -y gdisk e2fsprogs debootstrap nvme-cli
4459
}
4560

4661
# Partition the new root EBS volume

0 commit comments

Comments
 (0)