-
-
Save apsoto/329710 to your computer and use it in GitHub Desktop.
Delete ec2 terminated nodes from the chef server
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
#!/usr/bin/ruby | |
instances = `ec2-describe-instances --show-empty-fields` | |
lines = instances.split(/\n/) | |
running_instances = [] | |
lines.each do |lines| | |
if lines =~ /^INSTANCE/ | |
fields = lines.split(/\t/) | |
if fields[5] == 'running' | |
running_instances << fields[1] | |
running_instances << fields[4] | |
end | |
end | |
end | |
nodes = `knife node list` | |
nodes_arr = eval(nodes.gsub!(/\n/,'')) | |
puts "deleting the following nodes from chef server :" | |
(nodes_arr - running_instances).each do |n| | |
cmd = "knife node delete #{n} -y" | |
puts "\t #{cmd}" | |
puts `#{cmd}` | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment