bolt 1.49.0 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of bolt might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/Puppetfile +6 -6
- data/bolt-modules/boltlib/lib/puppet/datatypes/target.rb +24 -45
- data/bolt-modules/boltlib/lib/puppet/functions/add_facts.rb +3 -3
- data/bolt-modules/boltlib/lib/puppet/functions/add_to_group.rb +1 -1
- data/bolt-modules/boltlib/lib/puppet/functions/apply_prep.rb +10 -12
- data/bolt-modules/boltlib/lib/puppet/functions/catch_errors.rb +1 -1
- data/bolt-modules/boltlib/lib/puppet/functions/fail_plan.rb +3 -3
- data/bolt-modules/boltlib/lib/puppet/functions/get_resources.rb +5 -4
- data/bolt-modules/boltlib/lib/puppet/functions/get_target.rb +1 -3
- data/bolt-modules/boltlib/lib/puppet/functions/get_targets.rb +1 -2
- data/bolt-modules/boltlib/lib/puppet/functions/puppetdb_fact.rb +2 -2
- data/bolt-modules/boltlib/lib/puppet/functions/remove_from_group.rb +2 -2
- data/bolt-modules/boltlib/lib/puppet/functions/resolve_references.rb +1 -1
- data/bolt-modules/boltlib/lib/puppet/functions/run_command.rb +7 -3
- data/bolt-modules/boltlib/lib/puppet/functions/run_plan.rb +15 -31
- data/bolt-modules/boltlib/lib/puppet/functions/run_script.rb +9 -5
- data/bolt-modules/boltlib/lib/puppet/functions/run_task.rb +9 -3
- data/bolt-modules/boltlib/lib/puppet/functions/set_config.rb +4 -3
- data/bolt-modules/boltlib/lib/puppet/functions/set_feature.rb +6 -6
- data/bolt-modules/boltlib/lib/puppet/functions/set_var.rb +2 -2
- data/bolt-modules/boltlib/lib/puppet/functions/upload_file.rb +7 -3
- data/bolt-modules/boltlib/lib/puppet/functions/wait_until_available.rb +6 -2
- data/bolt-modules/boltlib/lib/puppet/functions/without_default_logging.rb +2 -2
- data/bolt-modules/ctrl/lib/puppet/functions/ctrl/do_until.rb +2 -1
- data/bolt-modules/file/lib/puppet/functions/file/exists.rb +2 -1
- data/bolt-modules/file/lib/puppet/functions/file/join.rb +1 -0
- data/bolt-modules/file/lib/puppet/functions/file/read.rb +1 -0
- data/bolt-modules/file/lib/puppet/functions/file/readable.rb +2 -1
- data/bolt-modules/out/lib/puppet/functions/out/message.rb +1 -1
- data/bolt-modules/system/lib/puppet/functions/system/env.rb +1 -0
- data/lib/bolt/applicator.rb +70 -118
- data/lib/bolt/apply_target.rb +1 -1
- data/lib/bolt/bolt_option_parser.rb +21 -37
- data/lib/bolt/catalog.rb +5 -22
- data/lib/bolt/catalog/logging.rb +1 -1
- data/lib/bolt/cli.rb +33 -44
- data/lib/bolt/config.rb +15 -18
- data/lib/bolt/error.rb +2 -2
- data/lib/bolt/executor.rb +32 -40
- data/lib/bolt/inventory.rb +9 -367
- data/lib/bolt/inventory/group.rb +293 -182
- data/lib/bolt/inventory/{inventory2.rb → inventory.rb} +25 -14
- data/lib/bolt/inventory/target.rb +1 -1
- data/lib/bolt/module.rb +4 -4
- data/lib/bolt/outputter/human.rb +11 -6
- data/lib/bolt/outputter/json.rb +3 -11
- data/lib/bolt/pal.rb +1 -2
- data/lib/bolt/pal/yaml_plan/step/resources.rb +1 -1
- data/lib/bolt/plugin.rb +1 -1
- data/lib/bolt/plugin/module.rb +19 -36
- data/lib/bolt/plugin/prompt.rb +2 -4
- data/lib/bolt/puppetdb/config.rb +1 -3
- data/lib/bolt/result.rb +3 -6
- data/lib/bolt/secret/base.rb +0 -6
- data/lib/bolt/target.rb +8 -219
- data/lib/bolt/transport/local/shell.rb +9 -13
- data/lib/bolt/transport/orch.rb +3 -5
- data/lib/bolt/transport/ssh.rb +1 -0
- data/lib/bolt/transport/ssh/connection.rb +1 -4
- data/lib/bolt/transport/winrm/connection.rb +1 -1
- data/lib/bolt/util.rb +2 -8
- data/lib/bolt/version.rb +1 -1
- data/lib/bolt_server/transport_app.rb +35 -17
- data/lib/bolt_spec/plans.rb +8 -2
- data/libexec/bolt_catalog +19 -5
- metadata +4 -8
- data/exe/bolt-inventory-pdb +0 -13
- data/lib/bolt/inventory/group2.rb +0 -403
- data/lib/bolt_ext/puppetdb_inventory.rb +0 -129
@@ -1,129 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
# frozen_string_literal: true
|
3
|
-
|
4
|
-
require 'bolt/puppetdb'
|
5
|
-
require 'bolt/logger'
|
6
|
-
require 'json'
|
7
|
-
require 'optparse'
|
8
|
-
require 'yaml'
|
9
|
-
|
10
|
-
module Bolt
|
11
|
-
class PuppetDBInventory
|
12
|
-
class CLI
|
13
|
-
def initialize(args)
|
14
|
-
Bolt::Logger.initialize_logging
|
15
|
-
@logger = Logging.logger[self]
|
16
|
-
@args = args
|
17
|
-
@cli_opts = {}
|
18
|
-
@parser = build_parser
|
19
|
-
end
|
20
|
-
|
21
|
-
def build_parser
|
22
|
-
parser = OptionParser.new('') do |opts|
|
23
|
-
opts.on('--cacert CACERT', "Path to the CA certificate") do |cacert|
|
24
|
-
@cli_opts['cacert'] = cacert
|
25
|
-
end
|
26
|
-
opts.on('--cert CERT', "Path to the certificate") do |cert|
|
27
|
-
@cli_opts['cert'] = cert
|
28
|
-
end
|
29
|
-
opts.on('--key KEY', "Path to the private key") do |key|
|
30
|
-
@cli_opts['key'] = key
|
31
|
-
end
|
32
|
-
opts.on('--token-file TOKEN',
|
33
|
-
"Path to the token file",
|
34
|
-
"Default: #{Bolt::PuppetDB::Config::DEFAULT_TOKEN} if present") do |token|
|
35
|
-
@cli_opts['token'] = token
|
36
|
-
end
|
37
|
-
opts.on('--url URL', "The URL of the PuppetDB server to connect to") do |url|
|
38
|
-
@cli_opts['server_urls'] = [url]
|
39
|
-
end
|
40
|
-
opts.on('--config CONFIG',
|
41
|
-
"The puppetdb.conf file to read configuration from",
|
42
|
-
"Defaults: #{Bolt::PuppetDB::Config::DEFAULT_CONFIG[:user]} or",
|
43
|
-
"#{Bolt::PuppetDB::Config::DEFAULT_CONFIG[:global]} if present") do |file|
|
44
|
-
@config_file = File.expand_path(file)
|
45
|
-
end
|
46
|
-
opts.on('--output FILE', '-o FILE',
|
47
|
-
"Where to write the generated inventory file, defaults to stdout") do |file|
|
48
|
-
@output_file = file
|
49
|
-
end
|
50
|
-
opts.on('--trace', "Show stacktraces for exceptions") do |trace|
|
51
|
-
@trace = trace
|
52
|
-
end
|
53
|
-
opts.on('-h', '--help', "Display help") do |_|
|
54
|
-
@show_help = true
|
55
|
-
end
|
56
|
-
end
|
57
|
-
parser.banner = <<-BANNER
|
58
|
-
Usage: bolt-inventory-pdb <input-file> [--output <output-file>] [--url <url>] [auth-options]
|
59
|
-
|
60
|
-
Populate the nodes in an inventory file based on PuppetDB queries.
|
61
|
-
|
62
|
-
The input file should be a Bolt inventory file, where each 'nodes' entry is
|
63
|
-
replaced with a 'query' entry to be executed against PuppetDB. The output will
|
64
|
-
be the input file, with the 'nodes' entry for each group populated with the
|
65
|
-
query results.
|
66
|
-
|
67
|
-
BANNER
|
68
|
-
parser
|
69
|
-
end
|
70
|
-
|
71
|
-
def run
|
72
|
-
Bolt::Logger.configure({ "console" => {} }, true)
|
73
|
-
msg = <<~MSG
|
74
|
-
Deprecation Warning: Starting with Bolt 2.0, inventory file v1 and the
|
75
|
-
bolt-inventory-pdb command will no longer be supported. Use a v2 inventory
|
76
|
-
file instead with the PuppetDB plugin to lookup targets from PuppetDB.
|
77
|
-
|
78
|
-
v1 inventory files can be automatically migrated to v2 using 'bolt project migrate'.
|
79
|
-
Inventory files are modified in place and will not preserve formatting or comments.
|
80
|
-
MSG
|
81
|
-
@logger.warn(msg)
|
82
|
-
|
83
|
-
positional_args = @parser.permute(@args)
|
84
|
-
|
85
|
-
if @show_help
|
86
|
-
puts @parser.help
|
87
|
-
return
|
88
|
-
end
|
89
|
-
|
90
|
-
inventory_file = positional_args.shift
|
91
|
-
unless inventory_file
|
92
|
-
raise "Please specify an input file (see --help for details)"
|
93
|
-
end
|
94
|
-
|
95
|
-
if positional_args.any?
|
96
|
-
raise "Unknown argument(s) #{positional_args.join(', ')}"
|
97
|
-
end
|
98
|
-
|
99
|
-
config = Bolt::PuppetDB::Config.load_config(@config_file, @cli_opts)
|
100
|
-
@puppetdb_client = Bolt::PuppetDB::Client.new(config)
|
101
|
-
|
102
|
-
unless File.readable?(inventory_file)
|
103
|
-
raise "Can't read the inventory file #{inventory_file}"
|
104
|
-
end
|
105
|
-
|
106
|
-
inventory = YAML.load_file(inventory_file)
|
107
|
-
resolve_group(inventory)
|
108
|
-
|
109
|
-
result = inventory.to_yaml
|
110
|
-
|
111
|
-
if @output_file
|
112
|
-
File.write(@output_file, result)
|
113
|
-
else
|
114
|
-
puts result
|
115
|
-
end
|
116
|
-
end
|
117
|
-
|
118
|
-
def resolve_group(group)
|
119
|
-
group['nodes'] = @puppetdb_client.query_certnames(group['query'])
|
120
|
-
|
121
|
-
group.fetch('groups', []).each do |child|
|
122
|
-
resolve_group(child)
|
123
|
-
end
|
124
|
-
|
125
|
-
group
|
126
|
-
end
|
127
|
-
end
|
128
|
-
end
|
129
|
-
end
|