Skip to content

Instantly share code, notes, and snippets.

@Aslan
Created March 11, 2010 03:10
Show Gist options
  • Save Aslan/328766 to your computer and use it in GitHub Desktop.
Save Aslan/328766 to your computer and use it in GitHub Desktop.
#!/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