forked from w3f/polkadot-validator-setup
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.sh
executable file
·56 lines (45 loc) · 1.29 KB
/
setup.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
#!/bin/bash
function handle_error() {
if (( $? )) ; then
echo -e "[\e[31mERROR\e[39m]"
echo -e >&2 "CAUSE:\n $1"
exit 1
else
echo -e "[\e[32mOK\e[39m]"
fi
}
cd "$(dirname "$0")"
echo "Sudo password for remote servers:"
read -s SUDO_PW
echo -n ">> Pulling upstream changes... "
out=$((git pull origin master) 2>&1)
handle_error "$out"
echo -n ">> Testing Ansible availability... "
out=$((ansible --version) 2>&1)
handle_error "$out"
echo -n ">> Finding validator hosts... "
out=$((ansible -i inventory.yml validator --list-hosts) 2>/dev/null)
if [[ $out == *"hosts (0)"* ]]; then
out="No hosts found, exiting..."
(exit 1)
handle_error "$out"
else
echo -e "[\e[32mOK\e[39m]"
echo "$out"
fi
echo -n ">> Finding public hosts... "
out=$((ansible -i inventory.yml public --list-hosts) 2>/dev/null)
if [[ $out == *"hosts (0)"* ]]; then
out="No hosts found, exiting..."
(exit 1)
handle_error "$out"
else
echo -e "[\e[32mOK\e[39m]"
echo "$out"
fi
echo -n ">> Testing connectivity to nodes... "
out=$((ansible all -i inventory.yml -m ping --become --extra-vars "ansible_become_pass='$SUDO_PW'") 2>&1)
handle_error "$out"
echo ">> Executing Ansible Playbook..."
ansible-playbook -i inventory.yml main.yml --become --extra-vars "ansible_become_pass='$SUDO_PW'"
echo ">> Done!"