diff --git a/fragments/bastion-node-cleanup.sh b/fragments/bastion-node-cleanup.sh index e46b5a6..bb3d4a5 100644 --- a/fragments/bastion-node-cleanup.sh +++ b/fragments/bastion-node-cleanup.sh @@ -20,7 +20,7 @@ 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 \ + 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 @@ -32,9 +32,11 @@ if [ -e $NODESFILE ]; then grep -v "$node_name" ${NODESFILE}.bkp > $NODESFILE || true fi -# unregister the node if registered with subscription-manager +# unregister the node if +# - node_id matches the one defined in deployment_bastion_node_cleanup +# - registered with subscription-manager [ -e $INVENTORY ] && ansible $node_name -m shell \ -u $ssh_user --sudo -i $INVENTORY \ - -a "subscription-manager unregister && subscription-manager clean" || true + -a "test -d /var/lib/cloud/instances/$node_id && echo "Cleanup node $node_id" >> /var/log/ansible-node-cleanup.log && subscription-manager unregister && subscription-manager clean" || true -echo "Deleted node $node_name" +echo "Deleted node $node_name with id $node_id" diff --git a/infra.yaml b/infra.yaml index 4daddb4..352a1ab 100644 --- a/infra.yaml +++ b/infra.yaml @@ -485,6 +485,7 @@ resources: properties: group: script inputs: + - name: node_id - name: node_name - name: node_type - name: ssh_user @@ -501,6 +502,7 @@ resources: properties: actions: ['DELETE'] input_values: + node_id: {get_resource: host} node_type: infra node_name: str_replace: diff --git a/loadbalancer_dedicated.yaml b/loadbalancer_dedicated.yaml index bc8b958..be6a638 100644 --- a/loadbalancer_dedicated.yaml +++ b/loadbalancer_dedicated.yaml @@ -395,6 +395,7 @@ resources: properties: group: script inputs: + - name: node_id - name: node_name - name: node_type - name: ssh_user @@ -411,6 +412,7 @@ resources: properties: actions: ['DELETE'] input_values: + node_id: {get_resource: host} node_type: loadbalancer node_name: str_replace: diff --git a/master.yaml b/master.yaml index 2942756..6abefac 100644 --- a/master.yaml +++ b/master.yaml @@ -477,6 +477,7 @@ resources: properties: group: script inputs: + - name: node_id - name: node_name - name: node_type - name: ssh_user @@ -493,6 +494,7 @@ resources: properties: actions: ['DELETE'] input_values: + node_id: {get_resource: host} node_type: master node_name: str_replace: diff --git a/node.yaml b/node.yaml index e1a8b3c..09662b2 100644 --- a/node.yaml +++ b/node.yaml @@ -587,6 +587,7 @@ resources: properties: group: script inputs: + - name: node_id - name: node_name - name: node_type - name: ssh_user @@ -603,6 +604,7 @@ resources: properties: actions: ['DELETE'] input_values: + node_id: {get_resource: host} node_type: node node_name: str_replace: