-
Notifications
You must be signed in to change notification settings - Fork 13
/
01_prepare_host.sh
executable file
·55 lines (44 loc) · 1.74 KB
/
01_prepare_host.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/usr/bin/env bash
set -eux
PROJECT_DIR=$(dirname -- $(readlink -e -- ${BASH_SOURCE[0]}))
if [[ "$(id -u)" -eq 0 ]]; then
echo "Please run as a non-root user"
exit 1
fi
# Check OS type and version
source /etc/os-release
export DISTRO="${ID}${VERSION_ID%.*}"
export OS="${ID}"
export OS_VERSION_ID="${VERSION_ID}"
export SUPPORTED_DISTROS=(ubuntu22 opensuse-leap15)
if [[ ! "${SUPPORTED_DISTROS[*]}" =~ ${DISTRO} ]]; then
echo "Supported OS distros for the host are: Ubuntu 22.04"
exit 1
fi
if [[ "${OS}" = "ubuntu" ]]; then
# Set apt retry limit to higher than default to
# make the data retrival more reliable
sudo sh -c ' echo "Acquire::Retries \"10\";" > /etc/apt/apt.conf.d/80-retries '
sudo DEBIAN_FRONTEND=noninteractive apt-get update
sudo DEBIAN_FRONTEND=noninteractive apt-get -y install python3-pip python3-dev jq curl wget pkg-config bash-completion
# Set update-alternatives to python3
if [[ "${DISTRO}" = "ubuntu22" ]]; then
sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.10 1
fi
elif [[ "${OS}" = "opensuse-leap" ]]; then
sudo zypper -n update
sudo zypper -n install python311 python311-pip jq curl wget pkg-config bash-completion
sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.11 1
fi
sudo python -m pip install ansible
# Install requirements
ansible-galaxy install -r requirements.yml
# Run ansible prepare host playbook
export ANSIBLE_ROLES_PATH=$PROJECT_DIR/roles
ANSIBLE_FORCE_COLOR=true ansible-playbook \
-i ${PROJECT_DIR}/inventories/localhost_inventory.yml \
$PROJECT_DIR/playbooks/prepare_host.yml $@
# Ensure we have an SSH key, used for access to VMs
if [ ! -f ~/.ssh/id_ed25519 ]; then
ssh-keygen -t ed25519 -C "m3-demo" -f ~/.ssh/id_ed25519 -N ""
fi