Add puppetsearch (compatible with 0.25.5).

This commit is contained in:
Ricky Zhou (周家杰) 2010-05-12 15:06:44 -04:00
parent b31f988560
commit bb8f5554b2

View file

@ -0,0 +1,57 @@
#!/usr/bin/ruby
require "yaml"
require "puppet"
require "optparse"
def find_resource(catalog, type, query_file)
resource = catalog.resource(type, query_file)
unless resource.nil?
resource.file
end
end
options = {
:types => [],
}
OptionParser.new do |opts|
opts.banner = "Usage: puppetsearch [options] title1 title2 ..."
opts.on("-y",
"--yamlfile YAMLFILE",
"Read catalog from YAMLFILE") do |yamlfile|
options[:yamlfile] = yamlfile
end
opts.on("-t",
"--types TYPES",
"Comma-separated list of resource types to search for") do |types|
options[:types] = types.split(',')
end
end.parse!
# Search for files by default.
if options[:types].empty?
options[:types] << "File"
end
if options[:yamlfile].nil?
require "facter"
fqdn = Facter.value(:fqdn)
if fqdn.nil?
abort "Error: Could not get FQDN"
end
options[:yamlfile] = "/var/lib/puppet/client_yaml/catalog/#{fqdn}.yaml"
end
catalog = YAML::load_file(options[:yamlfile])
ARGV.each do |search|
options[:types].each do |type|
manifest = find_resource(catalog, type, search)
puts "#{type}[#{search}] defined in #{manifest}"
end
end