-
Notifications
You must be signed in to change notification settings - Fork 83
Expand file tree
/
Copy pathbastion-node-cleanup.sh
More file actions
46 lines (36 loc) · 1.52 KB
/
bastion-node-cleanup.sh
File metadata and controls
46 lines (36 loc) · 1.52 KB
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
#!/bin/bash
# ENVVARS
# node_name = "<hostname>"
# Exit on fail or bad VAR expansion
set -eux
# ============================================================================
# MAIN
# ============================================================================
# used by ansible for setting ControlPath ssh param
export HOME=/root
INVENTORY=/var/lib/ansible/inventory
# evacuate all the pods and remove the node from the openshift service
# using the first master
if [ -e $INVENTORY -a "$node_type" == node ]; then
export ANSIBLE_ROLES_PATH=/usr/share/ansible/openshift-ansible/roles
export ANSIBLE_HOST_KEY_CHECKING=False
ansible-playbook -vvvv -e node=$node_name -e node_id=$node_id \
--inventory /var/lib/ansible/inventory \
/var/lib/ansible/playbooks/scaledown.yml &>> /var/log/ansible-scaledown.$$ || true
fi
# remove from the local list
NODESFILE=/var/lib/ansible/${node_type}_list
if [ -e $NODESFILE ]; then
cp $NODESFILE{,.bkp}
grep -v "$node_name" ${NODESFILE}.bkp > $NODESFILE || true
fi
# unregister the node if
# - node_id matches the one defined in deployment_bastion_node_cleanup
# - registered with subscription-manager
if [ -e $INVENTORY ]; then
echo "Cleanup node $node_name with $node_id" >> /var/log/ansible-node-cleanup.log
ansible $node_name -m shell \
-u $ssh_user --sudo -i $INVENTORY \
-a "test -d /var/lib/cloud/instances/$node_id && subscription-manager unregister && subscription-manager clean" || true
fi
echo "Deleted node $node_name with id $node_id"