Use puppet libraries to find catalog.
This commit is contained in:
parent
89e3c0d78f
commit
2e883c6be2
1 changed files with 17 additions and 20 deletions
|
@ -1,25 +1,32 @@
|
||||||
#!/usr/bin/ruby
|
#!/usr/bin/ruby
|
||||||
require "yaml"
|
|
||||||
require "puppet"
|
require "puppet"
|
||||||
require "optparse"
|
require "optparse"
|
||||||
|
|
||||||
options = {
|
options = {
|
||||||
|
:node => Puppet[:certname],
|
||||||
:types => [],
|
:types => [],
|
||||||
|
:source => :yaml,
|
||||||
}
|
}
|
||||||
|
|
||||||
OptionParser.new do |opts|
|
OptionParser.new do |opts|
|
||||||
opts.banner = "Usage: puppetsearch [options] title1 title2 ..."
|
opts.banner = "Usage: puppetsearch [options] title1 title2 ..."
|
||||||
|
|
||||||
opts.on("-y",
|
opts.on("-n",
|
||||||
"--yamlfile YAMLFILE",
|
"--node NODENAME",
|
||||||
"Read catalog from YAMLFILE") do |yamlfile|
|
"Search on node NODENAME") do |node|
|
||||||
options[:yamlfile] = yamlfile
|
options[:node] = node
|
||||||
end
|
end
|
||||||
|
|
||||||
opts.on("-t",
|
opts.on("-t",
|
||||||
"--types TYPES",
|
"--types TYPES",
|
||||||
"Comma-separated list of resource types to search for") do |types|
|
"Comma-separated list of resource types to search for") do |types|
|
||||||
options[:types] = types.split(',')
|
options[:types] = types.split(",")
|
||||||
|
end
|
||||||
|
|
||||||
|
opts.on("-s",
|
||||||
|
"--source SOURCE",
|
||||||
|
"Catalog source (yaml, compiler, rest, etc.)") do |source|
|
||||||
|
options[:source] = source
|
||||||
end
|
end
|
||||||
end.parse!
|
end.parse!
|
||||||
|
|
||||||
|
@ -28,24 +35,14 @@ if options[:types].empty?
|
||||||
options[:types] << "File"
|
options[:types] << "File"
|
||||||
end
|
end
|
||||||
|
|
||||||
if options[:yamlfile].nil?
|
Puppet[:catalog_terminus] = options[:source]
|
||||||
require "facter"
|
|
||||||
|
|
||||||
fqdn = Facter.value(:fqdn)
|
catalog = Puppet::Resource::Catalog.find(options[:node])
|
||||||
if fqdn.nil?
|
|
||||||
abort "Error: Could not determine FQDN"
|
|
||||||
end
|
|
||||||
|
|
||||||
client_yaml = Puppet[:clientyamldir]
|
if catalog.nil?
|
||||||
if client_yaml.nil?
|
abort "Could not load catalog."
|
||||||
abort "Could not determine client YAML directory."
|
|
||||||
end
|
|
||||||
|
|
||||||
options[:yamlfile] = "#{client_yaml}/catalog/#{fqdn}.yaml"
|
|
||||||
end
|
end
|
||||||
|
|
||||||
catalog = YAML::load_file(options[:yamlfile])
|
|
||||||
|
|
||||||
ARGV.each do |search_title|
|
ARGV.each do |search_title|
|
||||||
options[:types].each do |type|
|
options[:types].each do |type|
|
||||||
resource = catalog.resource(type, search_title)
|
resource = catalog.resource(type, search_title)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue