-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathconfigure.sh
69 lines (52 loc) · 1.52 KB
/
configure.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
#!/bin/bash
#
# Cluster init configuration script
#
#
# wait for cloud-init completion on the bastion host
#
execution=1
ssh_options="-i ~/.ssh/cluster.key -o StrictHostKeyChecking=no"
sudo cloud-init status --wait
#
# Install ansible and other required packages
#
source /etc/os-release
if [ $ID == "ol" ] ; then
repo="ol7_developer_EPEL"
else
repo="epel"
fi
# Install ansible and other required packages
sudo yum makecache --enablerepo=$repo
sudo yum install --enablerepo=$repo -y ansible python-netaddr
#
# A little waiter function to make sure all the nodes are up before we start configure
#
echo "Waiting for SSH to come up"
for host in $(cat /tmp/hosts) ; do
r=0
echo "validating connection to: ${host}"
while ! ssh ${ssh_options} opc@${host} uptime ; do
if [[ $r -eq 10 ]] ; then
execution=0
continue
fi
echo "Still waiting for ${host}"
sleep 60
r=$(($r + 1))
done
done
#
# Ansible will take care of key exchange and learning the host fingerprints, but for the first time we need
# to disable host key checking.
sed -i 's/^forks.*/forks = 128/' /etc/ansible/ansible.cfg
#
if [[ $execution -eq 1 ]] ; then
ANSIBLE_HOST_KEY_CHECKING=False ansible-playbook -vv /home/opc/playbooks/site.yml -i /home/opc/playbooks/inventory
else
cat <<- EOF > /etc/motd
At least one of the cluster nodes has been innacessible during installation. Please validate the hosts and re-run:
ANSIBLE_HOST_KEY_CHECKING=False ansible-playbook /home/opc/playbooks/site.yml -i /home/opc/playbooks/inventory
EOF
fi