Skip to content

Instantly share code, notes, and snippets.

@mitchellh
Created February 10, 2012 19:54
Show Gist options
  • Save mitchellh/1792217 to your computer and use it in GitHub Desktop.
Save mitchellh/1792217 to your computer and use it in GitHub Desktop.
Prune old clients.
#!/usr/bin/env ruby
require 'set'
def knife_list(type)
Set.new(`knife #{type} list`.split("\n").map { |a| a.strip.chomp })
end
nodes = knife_list(:node)
clients = knife_list(:client)
# We want to remove the clients that aren't nodes.
bad_clients = clients - nodes
bad_clients = bad_clients.to_a.sort
puts "Deleting #{bad_clients.length} stale clients."
bad_clients.each_index do |index|
bad_client = bad_clients[index]
puts "Deleting client #{index + 1}/#{bad_clients.length}: #{bad_client}"
`knife client delete #{bad_client} -y`
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment