Advertisement
Guest User

Untitled

a guest
Aug 21st, 2019
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.44 KB | None | 0 0
  1. #!/bin/bash
  2. # Scan for terminated nodes on AWS and remove from Chef
  3.  
  4. cleanupNodes() {
  5.  
  6. # get nodes that are terminated via aws-cli
  7. 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}')
  8.  
  9. for node in $terminated_nodes;
  10. do
  11. knife client delete ${node} -y && knife node delete ${node} -y
  12. done
  13. }
  14.  
  15. #main
  16. cleanupNodes()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement