-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.sh
executable file
·63 lines (50 loc) · 1.49 KB
/
install.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
56
57
58
59
60
61
62
63
#!/usr/bin/env bash
set -euo pipefail
[[ -z "${VERBOSE:-}" ]] || set -x
REPO_ROOT=$(git rev-parse --show-toplevel)
install_package() {
if [[ -f "/etc/debian-release" ]]; then
DEBIAN_FRONTEND=noninteractive sudo apt-get install --no-install-recommends -y "$@"
elif [[ -f "/etc/fedora-release" ]]; then
sudo dnf install -y "$@"
elif [[ -f "/etc/redhat-release" ]]; then
sudo yum install -y "$@"
else
echo "ERROR: Unsupported OS"
exit 1
fi
}
# Ensure python3 is available
if ! command -v python3; then
echo "INFO: installing python3"
install_package python3 python3-virtualenv python3-apt
fi
# Ensure virtualenv is available
if ! command -v virtualenv; then
echo "INFO: installing virtualenv"
install_package python3-virtualenv
fi
# Create a virtualenv
if [[ ! -d "${REPO_ROOT}/.venv" ]]; then
echo "INFO: Creating virtualenv"
virtualenv "${REPO_ROOT}/.venv"
fi
# Activate the virtualenv
source "${REPO_ROOT}/.venv/bin/activate"
# Check if Ansible is installed
if ! command -v ansible 2>&1>/dev/null; then
echo "INFO: Installing Ansible via pip"
python3 -m pip install ansible
fi
# Also install ansible-lint
if ! command -v ansible-lint 2>&1>/dev/null; then
echo "INFO: Installing ansible-lint via pip"
python3 -m pip install ansible-lint
fi
ANSIBLE_VERBOSE=""
if [[ -n "${VERBOSE:-}" ]]; then
ANSIBLE_VERBOSE="-vvv"
fi
# Run the playbook
cd "${REPO_ROOT}/ansible"
ansible-playbook playbook.yaml --forks $(nproc) ${ANSIBLE_VERBOSE}