Skip to content

Instantly share code, notes, and snippets.

@pivotalneutron
Created May 11, 2011 08:05
Show Gist options
  • Save pivotalneutron/966089 to your computer and use it in GitHub Desktop.
Save pivotalneutron/966089 to your computer and use it in GitHub Desktop.
Removing nodes & clients from chef server
numbers_to_delete = (10..20).to_a # or any array of numbers you need to operate on
name_prefix = 'server-name-prefix-' # will be used in a search, ie: "name:server-name-prefix-11"
names_to_delete = numbers_to_delete.map { |i| "#{name_prefix}#{i}" }
nodes_to_destroy = search(:node, names_to_delete.map { |n| "name:#{n}" }.join(" OR "))
nodes_to_destroy.each { |n| n.destroy }
clients_to_destroy = search(:client, names_to_delete.map { |n| "name:#{n}" }.join(" OR "))
clients_to_destroy.each { |c| c.destroy }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment