Puppet: System Administration Automated

Support

UsingStoredConfiguration: kill_node_in_storedconfigs_db.rb

File kill_node_in_storedconfigs_db.rb, 1.1 kB (added by jamtur01, 5 months ago)

Remove a host from the stored configuration database

Line 
1 #!/usr/bin/env ruby
2
3 ## Usage: sudo ./kill_node_in_storeconfigs_db.rb <hostname as stored in hosts table>
4
5 require 'puppet/rails'
6
7 Puppet[:config] = "/etc/puppet/puppet.conf"
8 Puppet.parse_config
9 pm_conf = Puppet.settings.instance_variable_get(:@values)[:puppetmasterd]
10
11 adapter = pm_conf[:dbadapter]
12 args = {:adapter => adapter, :log_level => pm_conf[:rails_loglevel]}
13
14 case adapter
15   when "sqlite3":
16     args[:dbfile] = pm_conf[:dblocation]
17   when "mysql", "postgresql":
18     args[:host]     = pm_conf[:dbserver] unless pm_conf[:dbserver].empty?
19     args[:username] = pm_conf[:dbuser] unless pm_conf[:dbuser].empty?
20     args[:password] = pm_conf[:dbpassword] unless pm_conf[:dbpassword].empty?
21     args[:database] = pm_conf[:dbname]
22     socket          = pm_conf[:dbsocket]
23     args[:socket]   = socket unless socket.empty?
24   else
25     raise ArgumentError, "Invalid db adapter %s" % adapter
26 end
27
28 ActiveRecord::Base.establish_connection(args)
29
30 if @host = Puppet::Rails::Host.find_by_name(ARGV[0].strip)
31   print "Killing #{ARGV[0]}..."
32   $stdout.flush
33   @host.destroy
34   puts "done."
35 else
36   puts "Can't find host #{ARGV[0]}."
37 end