-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathrebuild-k8s.sh
executable file
·36 lines (25 loc) · 1001 Bytes
/
rebuild-k8s.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
#!/bin/bash
SCRIPT_DIR=$(pwd)
ANSIBLE_DIR="ansible"
ANSIBLE_INVENTORY="ansible-inventory -i production"
ANSIBLE_ALL_HOSTS=$(cd ${ANSIBLE_DIR} && ${ANSIBLE_INVENTORY} --graph k8s_all | grep '|' | cut -d '-' -f3-6 | grep -v '@')
ANSIBLE_DOMAIN=$(cd ${ANSIBLE_DIR} && grep 'domain:' group_vars/all.yml | awk '{print $2}')
cd terraform/infrastructure/kubernetes || exit
terraform1.3 init -upgrade
terraform1.3 destroy -auto-approve
echo "Waiting 30s"
sleep 30
terraform1.3 apply -auto-approve
cd "${SCRIPT_DIR}" || exit
echo "Waiting 60s"
sleep 60
for host in ${ANSIBLE_ALL_HOSTS}; do
echo "Resetting SSH Host Keys: $host"
ipv4=$(cd ${ANSIBLE_DIR} && ${ANSIBLE_INVENTORY} -y --host "${host}" | grep 'ansible_host'| head -n 1 | awk '{print $2}')
ssh-keygen -R "${host}"."${ANSIBLE_DOMAIN}"
ssh-keygen -R "${ipv4}"
ssh-keyscan "${host}"."${ANSIBLE_DOMAIN}" >> ~/.ssh/known_hosts
ssh-keyscan "${ipv4}" >> ~/.ssh/known_hosts
done
cd ansible || exit
ansible-playbook -i production k8s-all.yml