18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
# File 'lib/bolt_ext/puppetdb_inventory.rb', line 18
def build_parser
parser = OptionParser.new('') do |opts|
opts.on('--cacert CACERT', "Path to the CA certificate") do |cacert|
@cli_opts['cacert'] = cacert
end
opts.on('--cert CERT', "Path to the certificate") do |cert|
@cli_opts['cert'] = cert
end
opts.on('--key KEY', "Path to the private key") do |key|
@cli_opts['key'] = key
end
opts.on('--token-file TOKEN',
"Path to the token file",
"Default: #{Bolt::PuppetDB::Config::DEFAULT_TOKEN} if present") do |token|
@cli_opts['token'] = token
end
opts.on('--url URL', "The URL of the PuppetDB server to connect to") do |url|
@cli_opts['server_urls'] = [url]
end
opts.on('--config CONFIG',
"The puppetdb.conf file to read configuration from",
"Defaults: #{Bolt::PuppetDB::Config::DEFAULT_CONFIG[:user]} or",
"#{Bolt::PuppetDB::Config::DEFAULT_CONFIG[:global]} if present") do |file|
@config_file = File.expand_path(file)
end
opts.on('--output FILE', '-o FILE',
"Where to write the generated inventory file, defaults to stdout") do |file|
@output_file = file
end
opts.on('--trace', "Show stacktraces for exceptions") do |trace|
@trace = trace
end
opts.on('-h', '--help', "Display help") do |_|
@show_help = true
end
end
parser.banner = <<-BANNER
Usage: bolt-inventory-pdb <input-file> [--output <output-file>] [--url <url>] [auth-options]
Populate the nodes in an inventory file based on PuppetDB queries.
The input file should be a Bolt inventory file, where each 'nodes' entry is
replaced with a 'query' entry to be executed against PuppetDB. The output will
be the input file, with the 'nodes' entry for each group populated with the
query results.
BANNER
parser
end
|