forked from oVirt/ovirt-system-tests
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup_for_ost.sh
executable file
·122 lines (108 loc) · 3.64 KB
/
setup_for_ost.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#!/bin/bash
usage() {
echo "Usage: $0 [-h|--help] [-y|--assume-yes] [ANSIBLE_EXTRA_VARS_FILE]"
echo
echo "For automated scenarios there's --assume-yes option (please note that it"
echo "will work only if you have passwordless sudo - otherwise you'll still need"
echo "to provide the sudo password interactively):"
echo
echo " ./setup_for_ost.sh -y"
echo
echo "some variables from the playbook can be overriden with a YAML/JSON"
echo "file (see the playbook and ansible for details):"
echo
echo " ./setup_for_ost.sh myvars.json"
echo
echo "where:"
echo
echo " $ cat myvars.json"
echo
echo " {"
echo ' "ost_images_repo_url": "http://other.repo.org/",'
echo ' "ost_images_rpms": ['
echo ' "ost-images-rhel8-engine-installed",'
echo ' "ost-images-rhel8-host-installed"'
echo " ]"
echo " }"
}
while [[ "${#}" -gt 0 ]]; do
case ${1} in
-y|--assume-yes)
ASSUME_YES=1
;;
-h|--help)
usage
exit 0
;;
*)
ANSIBLE_EXTRA_VARS_FILE="${1}"
;;
esac
shift
done
if [[ ${EUID} -eq 0 ]]; then
echo "This script should be run as a non-root user with sudo access."
exit 1
fi
source /etc/os-release
ANSIBLE_INSTALLED=$(which ansible-playbook &> /dev/null && echo 1 || echo 0)
ANSIBLE_PACKAGE=$(if [[ $VERSION == 9* ]]; then echo "ansible-core"; else echo "ansible"; fi)
ANSIBLE_REPO_RPM_URL=${ANSIBLE_REPO_RPM_URL:-"https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm"}
ANSIBLE_REPO_RPM_NAME=${ANSIBLE_REPO_RPM_NAME:-"epel-release-8"}
cleanup() {
if [[ ${REMOVE_ANSIBLE_REPO_RPM} -eq 1 ]]; then
sudo dnf remove -y "${ANSIBLE_REPO_RPM_NAME}"
fi
}
trap cleanup EXIT
if [[ ${ASSUME_YES} -ne 1 ]]; then
echo "You're running this setup as \"$(whoami)\" user"
echo "That means you will have to run OST (or use lago in general) as the same user."
echo "You will still be asked for sudo password during setup to run some commands as root."
echo
echo "Please note, that running OST requires ~6.5GBs of space on the root partition constantly"
echo "and around twice as much during 'dnf update'. If that's a problem, one way to work around"
echo "is to mount/symlink '/usr/share/ost-images' directory to something more capacious."
echo
read -p "Type 'y' if you want to continue " -n 1 -r
echo
if [[ ! ${REPLY} =~ ^[Yy]$ ]]; then
exit 0
fi
fi
if [[ ${ANSIBLE_INSTALLED} -eq 0 ]]; then
echo "This script needs ansible to work properly, will install it now..."
sudo dnf install -y "${ANSIBLE_PACKAGE}"
if [[ ${?} -ne 0 ]]; then
if [[ $VERSION == 9* ]]; then
echo "Ansible-core installation failed";
exit 1;
fi
REMOVE_ANSIBLE_REPO_RPM=1
sudo dnf -y install "${ANSIBLE_REPO_RPM_URL}" && sudo dnf install -y "${ANSIBLE_PACKAGE}"
fi
fi
echo "This script needs some ansible collections to work properly, will install them now..."
ansible-galaxy collection install ansible.posix community.general
if [[ ${?} -ne 0 ]]; then
echo "Ansible collection installation failed"
exit 1
fi
echo "Running the setup playbook..."
if [[ ${ASSUME_YES} -eq 1 ]]; then
ANSIBLE_ASK_SUDO_PASS_FLAG=""
else
ANSIBLE_ASK_SUDO_PASS_FLAG="-K"
fi
if [[ -n ${ANSIBLE_EXTRA_VARS_FILE} ]]; then
ANSIBLE_EXTRA_VARS_FLAG="-e"
ANSIBLE_EXTRA_VARS_FILE="@${ANSIBLE_EXTRA_VARS_FILE}"
else
ANSIBLE_EXTRA_VARS_FLAG=""
fi
ansible-playbook \
--connection=local \
-i 127.0.0.1, \
${ANSIBLE_ASK_SUDO_PASS_FLAG} \
${ANSIBLE_EXTRA_VARS_FLAG} ${ANSIBLE_EXTRA_VARS_FILE} \
common/setup/setup_playbook.yml