Created
August 9, 2019 08:43
-
-
Save acsrujan/2c77429eab3b0702af9dc178aa96e0f4 to your computer and use it in GitHub Desktop.
Cleans up terminated nodes from Chef server.. run it as cron on a server with both AWS access and Chef access, with knife installed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Scan for terminated nodes on AWS and remove from Chef | |
cleanupNodes() { | |
# get nodes that are terminated via aws-cli | |
terminated_nodes=$(aws ec2 describe-instances --region=us-east-1 --filters Name=instance-state-name,Values=terminated | grep "InstanceId" | awk -F ":" '{print $2}' | awk -F '"' '{print $2}') | |
for node in $terminated_nodes; | |
do | |
knife client delete ${node} -y && knife node delete ${node} -y | |
done | |
} | |
#main | |
cleanupNodes() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment