-
Notifications
You must be signed in to change notification settings - Fork 28
/
ha-deploy
executable file
·61 lines (51 loc) · 1.65 KB
/
ha-deploy
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
#!/bin/bash
set -e
# continue only if master node parameter is defined
if [ $# -lt 1 ]; then
echo "Usage: $0 <master_node>"
echo "Example: $0 mgmt01"
exit 1
fi
# master node name:
# also sync DB from this node
CLUSTER_MASTER_HOST="$1"
MAINDIR="$(cd "$(dirname "$0")/.." ; pwd -P)"
ERIGONES_HOME="${ERIGONES_HOME:-"${MAINDIR}"}"
ANS_BASE="${ERIGONES_HOME}/ans"
PLAYBOOK="${ANS_BASE}/ha/init-ha.yml"
HOSTS_FILE="${ANS_BASE}/hosts.cfg"
HOSTS_TMP_FILE="${ANS_BASE}/.hosts.cfg.tmp"
export ERIGONES_HOME
#PYTHONPATH="${ERIGONES_HOME}:${PYTHONPATH}:${ERIGONES_HOME}/envs/lib/python2.7/site-packages"
#VIRTUAL_ENV="${ERIGONES_HOME}/envs"
#export PYTHONPATH VIRTUAL_ENV
echo "Updating hosts.cfg.."
ZKCLI=/usbkey/scripts/zookeepercli
# get IP of mgmt01
if [ -f /usbkey/config ] && [ -x "${ZKCLI}" ]; then
#shellcheck disable=SC1091
. /usbkey/config
#shellcheck disable=SC2154
MGMT_IP="$("${ZKCLI}" -servers "${cfgdb_admin_ip}" -auth_usr "esdc" -auth_pwd "${esdc_install_password}" -c get /esdc/vms/esdc-mgmt/hosts/1/ip)"
fi
set +e
if [ -n "${MGMT_IP}" ]; then
# Update ansible inventory
ssh "root@${MGMT_IP}" "${ERIGONES_HOME}/bin/ctl.sh" genhosts --nodes --vms --pdc "admin" > "${HOSTS_TMP_FILE}"
if [ "x$?" == "x0" ]; then
# update succeeded
mv -f "${HOSTS_TMP_FILE}" "${HOSTS_FILE}"
else
echo "WARNING: Unable to update ansible hosts file. Trying to reuse the old one."
rm -f "${HOSTS_TMP_FILE}"
fi
else
echo "Unable to update hosts.cfg. Aborting."
exit 1
fi
set -e
# activate python virtualenv
# shellcheck disable=SC1090
. "${ERIGONES_HOME}/envs/bin/activate"
cd "${ANS_BASE}"
ansible-playbook "${PLAYBOOK}" --extra-vars "cluster_master_host=$CLUSTER_MASTER_HOST"