Skip to content

Instantly share code, notes, and snippets.

@maraca
Created May 13, 2014 06:35
Show Gist options
  • Save maraca/e9be0c8745b5ddb86568 to your computer and use it in GitHub Desktop.
Save maraca/e9be0c8745b5ddb86568 to your computer and use it in GitHub Desktop.
Chef deregistration service
#!/opt/chef/embedded/bin/ruby
#
# Author:: Adam Jacob (<adam@opscode.com>)
# Copyright:: Copyright (c) 2010 Opscode, Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
#
if File.exists?("/etc/chef/client.rb") && File.exists?("/usr/bin/chef-client")
require 'rubygems'
require 'chef'
require 'chef/knife'
require 'chef/knife/node_delete'
require 'chef/knife/client_delete'
Chef::Config.from_file("/etc/chef/client.rb")
Chef::Config[:node_name] = '<%= node.name %>'
nd = Chef::Knife::NodeDelete.new
nd.name_args = [ Chef::Config[:node_name] ]
nd.config[:yes] = true
nd.run
cd = Chef::Knife::ClientDelete.new
cd.name_args = [ Chef::Config[:node_name] ]
cd.config[:yes] = true
cd.run
File.unlink("/etc/chef/client.pem")
else
puts "This node is not connected to the Chef Master, no need to delete node."
end
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment