Add puppetsearch (compatible with 0.25.5).
This commit is contained in:
parent
b31f988560
commit
bb8f5554b2
1 changed files with 57 additions and 0 deletions
57
scripts/puppetsearch/puppetsearch.rb
Executable file
57
scripts/puppetsearch/puppetsearch.rb
Executable 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
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue