From a1fdae929371b08c45b76259d30ca864a76c831a Mon Sep 17 00:00:00 2001 From: Ossi Salmi Date: Thu, 2 Feb 2012 22:09:35 +0200 Subject: [PATCH] Added puppet-clean-storeconfigs script --- puppet/files/puppet-clean-storeconfigs | 40 ++++++++++++++++++++++++++ puppet/manifests/init.pp | 13 +++++++++ 2 files changed, 53 insertions(+) create mode 100755 puppet/files/puppet-clean-storeconfigs diff --git a/puppet/files/puppet-clean-storeconfigs b/puppet/files/puppet-clean-storeconfigs new file mode 100755 index 0000000..a5d7784 --- /dev/null +++ b/puppet/files/puppet-clean-storeconfigs @@ -0,0 +1,40 @@ +#!/usr/bin/env ruby + +require 'puppet/rails' + +if ARGV[0].nil? + puts "Usage: #{$0} " + exit +end + +Puppet[:config] = "/etc/puppet/puppet.conf" +Puppet.parse_config +pm_conf = Puppet.settings.instance_variable_get(:@values)[:master] + +adapter = pm_conf[:dbadapter] +args = {:adapter => adapter, :log_level => pm_conf[:rails_loglevel]} + +case adapter + when "sqlite3": + args[:database] = pm_conf[:dblocation] + when "mysql", "postgresql": + args[:host] = pm_conf[:dbserver] unless pm_conf[:dbserver].empty? + args[:username] = pm_conf[:dbuser] unless pm_conf[:dbuser].empty? + args[:password] = pm_conf[:dbpassword] unless pm_conf[:dbpassword].empty? + args[:database] = pm_conf[:dbname] + socket = pm_conf[:dbsocket] + args[:socket] = socket unless socket.empty? + else + raise ArgumentError, "Invalid db adapter %s" % adapter +end + +ActiveRecord::Base.establish_connection(args) + +if @host = Puppet::Rails::Host.find_by_name(ARGV[0].strip) + print "Killing #{ARGV[0]}..." + $stdout.flush + @host.destroy + puts "done." +else + puts "Can't find host #{ARGV[0]}." +end diff --git a/puppet/manifests/init.pp b/puppet/manifests/init.pp index fdf049c..6b2b794 100644 --- a/puppet/manifests/init.pp +++ b/puppet/manifests/init.pp @@ -368,6 +368,19 @@ class puppet::server::common inherits puppet::client { } } + if $puppet_storeconfigs != "none" { + file { "/usr/local/sbin/puppet-clean-storeconfigs": + ensure => present, + source => "puppet:///modules/puppet/puppet-clean-storeconfigs", + mode => 0755, + owner => "root", + group => $operatingsystem ? { + openbsd => "wheel", + default => "root", + }, + } + } + }