If a man speaks in a forest, and his wife's not there, is he still wrong?

Pulling information from puppet stored config DB, part 2

In my previous post, I started exploring how to pull information from a puppet stored config DB to use in capistrano, inspired by joe-mac's post.

Well, it seems that the query I used was overly complex. Here's the simplified version:

select h.name
from hosts h
join resources r on h.id = r.host_id
where r.restype = 'Class'
and r.title = 'site::profile::dnscache::local'
order by h.name;

Having established this, I then modified joe-mac's ruby script to look up based on Class rather than facts. Here's the modified script:

#!/usr/bin/env ruby

require 'getoptlong'
require 'puppet'
require 'rdoc/usage'

ActiveRecord::Base.establish_connection(
   :adapter  => 'mysql',
   :database => 'puppet',
   :host     => 'localhost',
   :password => 'secret',
   :username => 'puppet'
)

class Hosts < Puppet::Rails::Host; end

opts = GetoptLong.new(
   [ '--class',    '-c', GetoptLong::REQUIRED_ARGUMENT],
   [ '--help',     '-h', GetoptLong::NO_ARGUMENT ],
   [ '--print',    '-p', GetoptLong::REQUIRED_ARGUMENT]
       )

printtype = "name"
opt_hash = Hash.new()
opts.each do |opt, arg|
   case opt
      when '--class'
         opt_hash['class'] = arg
      when '--help'
         RDoc::usage
      when '--print'
         printtype = arg
   end
end

query = "(resources.restype = \'Class\' AND resources.title = \'#{opt_hash['class']}\')"

puts Hosts.find(:all,
                :include    => [ :resources ],
                :conditions => query
               ).map { |host| host.send(printtype) }

Next step: build this into my capistrano configuration as per joe-mac's example.

 

What's Related

Story Options

Pulling information from puppet stored config DB, part 2 | 0 comments
The following comments are owned by whomever posted them. This site is not responsible for what they say.

Topics

  • Home
  • Misc (6/0)
  • Audio (5/0)
  • Linux (21/0)
  • Family (1/0)
  • Fishing Diary (1/0)
  • OpenSolaris (7/0)
  • Computing (11/0)
  • General News (7/0)
  • Chloe (1/0)
  • Emily (2/0)
  • Twins (5/0)
  • Classifieds (2/0)
  • GeekLog (2/0)
  • Project Management (1/0)
  • User Functions






    Lost your password?