-
Notifications
You must be signed in to change notification settings - Fork 4
/
configure.sh
68 lines (53 loc) · 1.71 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
#!/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
#
sudo yum makecache
sudo yum install -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
break
fi
echo "Still waiting for ${host}"
sleep 60
r=$(($r + 1))
done
done
# Update the forks to a 8 * threads
threads=$(nproc)
forks=$(($threads * 8))
sudo sed -i "s/^#forks.*/forks = ${forks}/" /etc/ansible/ansible.cfg
sudo sed -i "s/^#fact_caching=.*/fact_caching=jsonfile/" /etc/ansible/ansible.cfg
sudo sed -i "s/^#fact_caching_connection.*/fact_caching_connection=\/tmp\/ansible/" /etc/ansible/ansible.cfg
sudo mv /home/opc/playbooks/inventory /etc/ansible/hosts
#
# Ansible will take care of key exchange and learning the host fingerprints, but for the first time we need
# to disable host key checking.
#
if [[ $execution -eq 1 ]] ; then
ANSIBLE_HOST_KEY_CHECKING=False ansible all -m setup --tree /tmp/ansible
ANSIBLE_HOST_KEY_CHECKING=False ansible-playbook /home/opc/playbooks/site.yml
else
cat <<- EOF > /tmp/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
EOF
sudo mv /tmp/motd /etc/motd
fi