bolt 2.14.0 → 2.19.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 +1 -1
- data/bolt-modules/boltlib/lib/puppet/functions/add_facts.rb +1 -0
- data/bolt-modules/boltlib/lib/puppet/functions/add_to_group.rb +1 -0
- data/bolt-modules/boltlib/lib/puppet/functions/apply_prep.rb +20 -9
- data/bolt-modules/boltlib/lib/puppet/functions/catch_errors.rb +1 -0
- data/bolt-modules/boltlib/lib/puppet/functions/facts.rb +1 -0
- data/bolt-modules/boltlib/lib/puppet/functions/fail_plan.rb +1 -0
- data/bolt-modules/boltlib/lib/puppet/functions/get_resources.rb +1 -0
- data/bolt-modules/boltlib/lib/puppet/functions/get_target.rb +1 -0
- data/bolt-modules/boltlib/lib/puppet/functions/get_targets.rb +1 -0
- data/bolt-modules/boltlib/lib/puppet/functions/puppetdb_fact.rb +1 -0
- data/bolt-modules/boltlib/lib/puppet/functions/puppetdb_query.rb +1 -0
- data/bolt-modules/boltlib/lib/puppet/functions/remove_from_group.rb +1 -0
- data/bolt-modules/boltlib/lib/puppet/functions/resolve_references.rb +1 -0
- data/bolt-modules/boltlib/lib/puppet/functions/resource.rb +1 -0
- data/bolt-modules/boltlib/lib/puppet/functions/run_command.rb +3 -0
- data/bolt-modules/boltlib/lib/puppet/functions/run_plan.rb +2 -1
- data/bolt-modules/boltlib/lib/puppet/functions/run_script.rb +7 -4
- data/bolt-modules/boltlib/lib/puppet/functions/run_task.rb +2 -1
- data/bolt-modules/boltlib/lib/puppet/functions/set_config.rb +1 -0
- data/bolt-modules/boltlib/lib/puppet/functions/set_feature.rb +1 -0
- data/bolt-modules/boltlib/lib/puppet/functions/set_resources.rb +1 -0
- data/bolt-modules/boltlib/lib/puppet/functions/set_var.rb +1 -0
- data/bolt-modules/boltlib/lib/puppet/functions/upload_file.rb +1 -0
- data/bolt-modules/boltlib/lib/puppet/functions/vars.rb +1 -0
- data/bolt-modules/boltlib/lib/puppet/functions/wait_until_available.rb +1 -0
- data/bolt-modules/boltlib/lib/puppet/functions/without_default_logging.rb +1 -0
- data/bolt-modules/boltlib/lib/puppet/functions/write_file.rb +1 -0
- data/bolt-modules/ctrl/lib/puppet/functions/ctrl/do_until.rb +2 -0
- data/bolt-modules/ctrl/lib/puppet/functions/ctrl/sleep.rb +2 -0
- data/bolt-modules/file/lib/puppet/functions/file/exists.rb +2 -1
- data/bolt-modules/file/lib/puppet/functions/file/join.rb +2 -0
- data/bolt-modules/file/lib/puppet/functions/file/read.rb +3 -1
- data/bolt-modules/file/lib/puppet/functions/file/readable.rb +3 -1
- data/bolt-modules/file/lib/puppet/functions/file/write.rb +2 -0
- data/bolt-modules/out/lib/puppet/functions/out/message.rb +2 -0
- data/bolt-modules/prompt/lib/puppet/functions/prompt.rb +1 -0
- data/bolt-modules/system/lib/puppet/functions/system/env.rb +2 -0
- data/lib/bolt/applicator.rb +34 -20
- data/lib/bolt/apply_result.rb +1 -1
- data/lib/bolt/bolt_option_parser.rb +30 -18
- data/lib/bolt/cli.rb +78 -56
- data/lib/bolt/config.rb +158 -128
- data/lib/bolt/config/options.rb +474 -0
- data/lib/bolt/config/transport/base.rb +16 -16
- data/lib/bolt/config/transport/docker.rb +9 -23
- data/lib/bolt/config/transport/local.rb +6 -44
- data/lib/bolt/config/transport/options.rb +460 -0
- data/lib/bolt/config/transport/orch.rb +9 -18
- data/lib/bolt/config/transport/remote.rb +3 -6
- data/lib/bolt/config/transport/ssh.rb +74 -154
- data/lib/bolt/config/transport/winrm.rb +18 -47
- data/lib/bolt/inventory/group.rb +1 -1
- data/lib/bolt/inventory/inventory.rb +0 -14
- data/lib/bolt/inventory/target.rb +18 -5
- data/lib/bolt/logger.rb +24 -1
- data/lib/bolt/outputter.rb +3 -0
- data/lib/bolt/outputter/rainbow.rb +90 -0
- data/lib/bolt/pal.rb +23 -9
- data/lib/bolt/pal/yaml_plan/evaluator.rb +1 -1
- data/lib/bolt/plugin/module.rb +2 -4
- data/lib/bolt/project.rb +41 -52
- data/lib/bolt/shell/bash.rb +30 -42
- data/lib/bolt/shell/powershell.rb +13 -8
- data/lib/bolt/shell/powershell/snippets.rb +15 -6
- data/lib/bolt/transport/docker.rb +9 -5
- data/lib/bolt/transport/orch.rb +8 -0
- data/lib/bolt/transport/ssh.rb +7 -1
- data/lib/bolt/transport/ssh/exec_connection.rb +1 -1
- data/lib/bolt/version.rb +1 -1
- metadata +18 -15
data/lib/bolt/config.rb
CHANGED
@@ -6,13 +6,7 @@ require 'pathname'
|
|
6
6
|
require 'bolt/project'
|
7
7
|
require 'bolt/logger'
|
8
8
|
require 'bolt/util'
|
9
|
-
|
10
|
-
require 'bolt/config/transport/ssh'
|
11
|
-
require 'bolt/config/transport/winrm'
|
12
|
-
require 'bolt/config/transport/orch'
|
13
|
-
require 'bolt/config/transport/local'
|
14
|
-
require 'bolt/config/transport/docker'
|
15
|
-
require 'bolt/config/transport/remote'
|
9
|
+
require 'bolt/config/options'
|
16
10
|
|
17
11
|
module Bolt
|
18
12
|
class UnknownTransportError < Bolt::Error
|
@@ -23,95 +17,18 @@ module Bolt
|
|
23
17
|
end
|
24
18
|
|
25
19
|
class Config
|
26
|
-
|
27
|
-
|
28
|
-
TRANSPORT_CONFIG = {
|
29
|
-
'ssh' => Bolt::Config::Transport::SSH,
|
30
|
-
'winrm' => Bolt::Config::Transport::WinRM,
|
31
|
-
'pcp' => Bolt::Config::Transport::Orch,
|
32
|
-
'local' => Bolt::Config::Transport::Local,
|
33
|
-
'docker' => Bolt::Config::Transport::Docker,
|
34
|
-
'remote' => Bolt::Config::Transport::Remote
|
35
|
-
}.freeze
|
36
|
-
|
37
|
-
TRANSPORT_OPTION = { 'transport' => 'The default transport to use when the '\
|
38
|
-
'transport for a target is not specified in the URL.' }.freeze
|
39
|
-
|
40
|
-
DEFAULT_TRANSPORT_OPTION = { 'transport' => 'ssh' }.freeze
|
41
|
-
|
42
|
-
CONFIG_IN_INVENTORY = TRANSPORT_CONFIG.merge(TRANSPORT_OPTION)
|
43
|
-
|
44
|
-
# NOTE: All configuration options should have a corresponding schema property
|
45
|
-
# in schemas/bolt-config.schema.json
|
46
|
-
OPTIONS = {
|
47
|
-
"apply_settings" => "A map of Puppet settings to use when applying Puppet code",
|
48
|
-
"color" => "Whether to use colored output when printing messages to the console.",
|
49
|
-
"compile-concurrency" => "The maximum number of simultaneous manifest block compiles.",
|
50
|
-
"concurrency" => "The number of threads to use when executing on remote targets.",
|
51
|
-
"format" => "The format to use when printing results. Options are `human` and `json`.",
|
52
|
-
"hiera-config" => "The path to your Hiera config.",
|
53
|
-
"inventoryfile" => "The path to a structured data inventory file used to refer to groups of "\
|
54
|
-
"targets on the command line and from plans.",
|
55
|
-
"log" => "The configuration of the logfile output. Configuration can be set for "\
|
56
|
-
"`console` and the path to a log file, such as `~/.puppetlabs/bolt/debug.log`.",
|
57
|
-
"modulepath" => "An array of directories that Bolt loads content (e.g. plans and tasks) from.",
|
58
|
-
"plugin_hooks" => "Which plugins a specific hook should use.",
|
59
|
-
"plugins" => "A map of plugins and their configuration data.",
|
60
|
-
"puppetdb" => "A map containing options for configuring the Bolt PuppetDB client.",
|
61
|
-
"puppetfile" => "A map containing options for the `bolt puppetfile install` command.",
|
62
|
-
"save-rerun" => "Whether to update `.rerun.json` in the Bolt project directory. If "\
|
63
|
-
"your target names include passwords, set this value to `false` to avoid "\
|
64
|
-
"writing passwords to disk.",
|
65
|
-
"transport" => "The default transport to use when the transport for a target is not specified "\
|
66
|
-
"in the URL or inventory.",
|
67
|
-
"trusted-external-command" => "The path to an executable on the Bolt controller that can produce "\
|
68
|
-
"external trusted facts. **External trusted facts are experimental in both "\
|
69
|
-
"Puppet and Bolt and this API may change or be removed.**"
|
70
|
-
}.freeze
|
71
|
-
|
72
|
-
DEFAULT_OPTIONS = {
|
73
|
-
"color" => true,
|
74
|
-
"compile-concurrency" => "Number of cores",
|
75
|
-
"concurrency" => "100 or one-third of the ulimit, whichever is lower",
|
76
|
-
"format" => "human",
|
77
|
-
"hiera-config" => "Boltdir/hiera.yaml",
|
78
|
-
"inventoryfile" => "Boltdir/inventory.yaml",
|
79
|
-
"modulepath" => ["Boltdir/modules", "Boltdir/site-modules", "Boltdir/site"],
|
80
|
-
"save-rerun" => true
|
81
|
-
}.freeze
|
82
|
-
|
83
|
-
PUPPETFILE_OPTIONS = {
|
84
|
-
"forge" => "A subsection that can have its own `proxy` setting to set an HTTP proxy for Forge operations "\
|
85
|
-
"only, and a `baseurl` setting to specify a different Forge host.",
|
86
|
-
"proxy" => "The HTTP proxy to use for Git and Forge operations."
|
87
|
-
}.freeze
|
88
|
-
|
89
|
-
LOG_OPTIONS = {
|
90
|
-
"append" => "Add output to an existing log file. Available only for logs output to a "\
|
91
|
-
"filepath.",
|
92
|
-
"level" => "The type of information in the log. Either `debug`, `info`, `notice`, "\
|
93
|
-
"`warn`, or `error`."
|
94
|
-
}.freeze
|
95
|
-
|
96
|
-
DEFAULT_LOG_OPTIONS = {
|
97
|
-
"append" => true,
|
98
|
-
"level" => "`warn` for console, `notice` for file"
|
99
|
-
}.freeze
|
100
|
-
|
101
|
-
APPLY_SETTINGS = {
|
102
|
-
"show_diff" => "Whether to log and report a contextual diff when files are being replaced. "\
|
103
|
-
"See [Puppet documentation](https://puppet.com/docs/puppet/latest/configuration.html#showdiff) "\
|
104
|
-
"for details"
|
105
|
-
}.freeze
|
106
|
-
|
107
|
-
DEFAULT_APPLY_SETTINGS = {
|
108
|
-
"show_diff" => false
|
109
|
-
}.freeze
|
20
|
+
include Bolt::Config::Options
|
110
21
|
|
22
|
+
attr_reader :config_files, :warnings, :data, :transports, :project, :modified_concurrency, :deprecations
|
23
|
+
|
24
|
+
BOLT_CONFIG_NAME = 'bolt.yaml'
|
25
|
+
BOLT_DEFAULTS_NAME = 'bolt-defaults.yaml'
|
26
|
+
|
27
|
+
# The default concurrency value that is used when the ulimit is not low (i.e. < 700)
|
111
28
|
DEFAULT_DEFAULT_CONCURRENCY = 100
|
112
29
|
|
113
30
|
def self.default
|
114
|
-
new(Bolt::Project.
|
31
|
+
new(Bolt::Project.default_project, {})
|
115
32
|
end
|
116
33
|
|
117
34
|
def self.from_project(project, overrides = {})
|
@@ -121,57 +38,164 @@ module Bolt
|
|
121
38
|
Bolt::Util.read_optional_yaml_hash(project.config_file, 'config')
|
122
39
|
end
|
123
40
|
|
124
|
-
data =
|
125
|
-
|
126
|
-
|
41
|
+
data = load_defaults(project).push(
|
42
|
+
filepath: project.config_file,
|
43
|
+
data: conf,
|
44
|
+
warnings: [],
|
45
|
+
deprecations: []
|
46
|
+
)
|
127
47
|
|
128
48
|
new(project, data, overrides)
|
129
49
|
end
|
130
50
|
|
131
51
|
def self.from_file(configfile, overrides = {})
|
132
52
|
project = Bolt::Project.create_project(Pathname.new(configfile).expand_path.dirname)
|
53
|
+
|
133
54
|
conf = if project.project_file == project.config_file
|
134
55
|
project.data
|
135
56
|
else
|
136
57
|
Bolt::Util.read_yaml_hash(configfile, 'config')
|
137
58
|
end
|
138
|
-
|
139
|
-
data = load_defaults(project).push(
|
59
|
+
|
60
|
+
data = load_defaults(project).push(
|
61
|
+
filepath: project.config_file,
|
62
|
+
data: conf,
|
63
|
+
warnings: [],
|
64
|
+
deprecations: []
|
65
|
+
)
|
140
66
|
|
141
67
|
new(project, data, overrides)
|
142
68
|
end
|
143
69
|
|
144
|
-
def self.
|
70
|
+
def self.system_path
|
145
71
|
# Lazy-load expensive gem code
|
146
72
|
require 'win32/dir' if Bolt::Util.windows?
|
147
73
|
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
74
|
+
if Bolt::Util.windows?
|
75
|
+
Pathname.new(File.join(Dir::COMMON_APPDATA, 'PuppetLabs', 'bolt', 'etc'))
|
76
|
+
else
|
77
|
+
Pathname.new(File.join('/etc', 'puppetlabs', 'bolt'))
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
def self.user_path
|
82
|
+
Pathname.new(File.expand_path(File.join('~', '.puppetlabs', 'etc', 'bolt')))
|
83
|
+
rescue StandardError
|
84
|
+
nil
|
85
|
+
end
|
86
|
+
|
87
|
+
# Loads a 'bolt-defaults.yaml' file, which contains default configuration that applies to all
|
88
|
+
# projects. This file does not allow project-specific configuration such as 'hiera-config' and
|
89
|
+
# 'inventoryfile', and nests all default inventory configuration under an 'inventory-config' key.
|
90
|
+
def self.load_bolt_defaults_yaml(dir)
|
91
|
+
filepath = dir + BOLT_DEFAULTS_NAME
|
92
|
+
data = Bolt::Util.read_yaml_hash(filepath, 'config')
|
93
|
+
warnings = []
|
94
|
+
|
95
|
+
# Warn if 'bolt.yaml' detected in same directory.
|
96
|
+
if File.exist?(bolt_yaml = dir + BOLT_CONFIG_NAME)
|
97
|
+
warnings.push(
|
98
|
+
msg: "Detected multiple configuration files: ['#{bolt_yaml}', '#{filepath}']. '#{bolt_yaml}' "\
|
99
|
+
"will be ignored."
|
100
|
+
)
|
101
|
+
end
|
102
|
+
|
103
|
+
# Remove project-specific config such as hiera-config, etc.
|
104
|
+
project_config = data.slice(*(BOLT_PROJECT_OPTIONS - BOLT_DEFAULTS_OPTIONS))
|
105
|
+
|
106
|
+
if project_config.any?
|
107
|
+
data.reject! { |key, _| project_config.include?(key) }
|
108
|
+
warnings.push(
|
109
|
+
msg: "Unsupported project configuration detected in '#{filepath}': #{project_config.keys}. "\
|
110
|
+
"Project configuration should be set in 'bolt-project.yaml'."
|
111
|
+
)
|
112
|
+
end
|
113
|
+
|
114
|
+
# Remove top-level transport config such as transport, ssh, etc.
|
115
|
+
transport_config = data.slice(*INVENTORY_OPTIONS.keys)
|
116
|
+
|
117
|
+
if transport_config.any?
|
118
|
+
data.reject! { |key, _| transport_config.include?(key) }
|
119
|
+
warnings.push(
|
120
|
+
msg: "Unsupported inventory configuration detected in '#{filepath}': #{transport_config.keys}. "\
|
121
|
+
"Transport configuration should be set under the 'inventory-config' option or "\
|
122
|
+
"in 'inventory.yaml'."
|
123
|
+
)
|
124
|
+
end
|
125
|
+
|
126
|
+
# Move data under inventory-config to top-level so it can be easily merged with
|
127
|
+
# config from other sources. Error early if inventory-config is not a hash or
|
128
|
+
# has a plugin reference.
|
129
|
+
if data.key?('inventory-config')
|
130
|
+
unless data['inventory-config'].is_a?(Hash)
|
131
|
+
raise Bolt::ValidationError,
|
132
|
+
"Option 'inventory-config' must be of type Hash, received #{data['inventory-config']} "\
|
133
|
+
"#{data['inventory-config']} (file: #{filepath})"
|
134
|
+
end
|
135
|
+
|
136
|
+
if data['inventory-config'].key?('_plugin')
|
137
|
+
raise Bolt::ValidationError,
|
138
|
+
"Found unsupported key '_plugin' for option 'inventory-config'; supported keys are "\
|
139
|
+
"'#{INVENTORY_OPTIONS.keys.join("', '")}' (file: #{filepath})"
|
140
|
+
end
|
141
|
+
|
142
|
+
data = data.merge(data.delete('inventory-config'))
|
143
|
+
end
|
144
|
+
|
145
|
+
{ filepath: filepath, data: data, warnings: warnings, deprecations: [] }
|
146
|
+
end
|
147
|
+
|
148
|
+
# Loads a 'bolt.yaml' file, the legacy configuration file. There's no special munging needed
|
149
|
+
# here since Bolt::Config will just ignore any invalid keys.
|
150
|
+
def self.load_bolt_yaml(dir)
|
151
|
+
filepath = dir + BOLT_CONFIG_NAME
|
152
|
+
data = Bolt::Util.read_yaml_hash(filepath, 'config')
|
153
|
+
deprecations = [{ type: 'Using bolt.yaml for system configuration',
|
154
|
+
msg: "Configuration file #{filepath} is deprecated and will be removed in a future version "\
|
155
|
+
"of Bolt. Use '#{dir + BOLT_DEFAULTS_NAME}' instead." }]
|
156
|
+
|
157
|
+
{ filepath: filepath, data: data, warnings: [], deprecations: deprecations }
|
158
|
+
end
|
159
|
+
|
160
|
+
def self.load_defaults(project)
|
161
|
+
confs = []
|
162
|
+
|
163
|
+
# Load system-level config. Prefer a 'bolt-defaults.yaml' file, but fall back to the
|
164
|
+
# legacy 'bolt.yaml' file. If the project-level config file is also the system-level
|
165
|
+
# config file, don't load it a second time.
|
166
|
+
if File.exist?(system_path + BOLT_DEFAULTS_NAME)
|
167
|
+
confs << load_bolt_defaults_yaml(system_path)
|
168
|
+
elsif File.exist?(system_path + BOLT_CONFIG_NAME) &&
|
169
|
+
(system_path + BOLT_CONFIG_NAME) != project.config_file
|
170
|
+
confs << load_bolt_yaml(system_path)
|
171
|
+
end
|
172
|
+
|
173
|
+
# Load user-level config if there is a homedir. Prefer a 'bolt-defaults.yaml' file, but
|
174
|
+
# fall back to the legacy 'bolt.yaml' file.
|
175
|
+
if user_path
|
176
|
+
if File.exist?(user_path + BOLT_DEFAULTS_NAME)
|
177
|
+
confs << load_bolt_defaults_yaml(user_path)
|
178
|
+
elsif File.exist?(user_path + BOLT_CONFIG_NAME)
|
179
|
+
confs << load_bolt_yaml(user_path)
|
180
|
+
end
|
181
|
+
end
|
182
|
+
|
163
183
|
confs
|
164
184
|
end
|
165
185
|
|
166
186
|
def initialize(project, config_data, overrides = {})
|
167
187
|
unless config_data.is_a?(Array)
|
168
|
-
config_data = [{ filepath: project.config_file,
|
188
|
+
config_data = [{ filepath: project.config_file,
|
189
|
+
data: config_data,
|
190
|
+
warnings: [],
|
191
|
+
deprecations: [] }]
|
169
192
|
end
|
170
193
|
|
171
|
-
@logger
|
172
|
-
@project
|
173
|
-
@warnings
|
174
|
-
@
|
194
|
+
@logger = Logging.logger[self]
|
195
|
+
@project = project
|
196
|
+
@warnings = @project.warnings.dup
|
197
|
+
@deprecations = @project.deprecations.dup
|
198
|
+
@transports = {}
|
175
199
|
@config_files = []
|
176
200
|
|
177
201
|
default_data = {
|
@@ -189,9 +213,14 @@ module Bolt
|
|
189
213
|
'transport' => 'ssh'
|
190
214
|
}
|
191
215
|
|
192
|
-
loaded_data = config_data.
|
193
|
-
@
|
194
|
-
|
216
|
+
loaded_data = config_data.each_with_object([]) do |data, acc|
|
217
|
+
@warnings.concat(data[:warnings]) if data[:warnings].any?
|
218
|
+
@deprecations.concat(data[:deprecations]) if data[:deprecations].any?
|
219
|
+
|
220
|
+
if data[:data].any?
|
221
|
+
@config_files.push(data[:filepath])
|
222
|
+
acc.push(data[:data])
|
223
|
+
end
|
195
224
|
end
|
196
225
|
|
197
226
|
override_data = normalize_overrides(overrides)
|
@@ -217,12 +246,13 @@ module Bolt
|
|
217
246
|
def normalize_overrides(options)
|
218
247
|
opts = options.transform_keys(&:to_s)
|
219
248
|
|
220
|
-
# Pull out config options
|
221
|
-
|
249
|
+
# Pull out config options. We need to add 'transport' as it's not part of the
|
250
|
+
# OPTIONS hash but is a valid option that can be set with the --transport CLI option
|
251
|
+
overrides = opts.slice(*OPTIONS.keys, 'transport')
|
222
252
|
|
223
253
|
# Pull out transport config options
|
224
254
|
TRANSPORT_CONFIG.each do |transport, config|
|
225
|
-
overrides[transport] = opts.slice(*config.options
|
255
|
+
overrides[transport] = opts.slice(*config.options)
|
226
256
|
end
|
227
257
|
|
228
258
|
# Set console log to debug if in debug mode
|
@@ -289,8 +319,8 @@ module Bolt
|
|
289
319
|
end
|
290
320
|
|
291
321
|
# Filter hashes to only include valid options
|
292
|
-
@data['apply_settings'] = @data['apply_settings'].slice(*
|
293
|
-
@data['puppetfile'] = @data['puppetfile'].slice(*
|
322
|
+
@data['apply_settings'] = @data['apply_settings'].slice(*OPTIONS['apply_settings'][:properties].keys)
|
323
|
+
@data['puppetfile'] = @data['puppetfile'].slice(*OPTIONS['puppetfile'][:properties].keys)
|
294
324
|
end
|
295
325
|
|
296
326
|
private def normalize_log(target)
|
@@ -304,7 +334,7 @@ module Bolt
|
|
304
334
|
next unless val.is_a?(Hash)
|
305
335
|
|
306
336
|
name = normalize_log(key)
|
307
|
-
acc[name] = val.slice(
|
337
|
+
acc[name] = val.slice('append', 'level')
|
308
338
|
.transform_keys(&:to_sym)
|
309
339
|
|
310
340
|
if (v = acc[name][:level])
|
@@ -356,7 +386,7 @@ module Bolt
|
|
356
386
|
raise Bolt::ValidationError, "Compilation is CPU-intensive, set concurrency less than #{compile_limit}"
|
357
387
|
end
|
358
388
|
|
359
|
-
unless %w[human json].include? format
|
389
|
+
unless %w[human json rainbow].include? format
|
360
390
|
raise Bolt::ValidationError, "Unsupported format: '#{format}'"
|
361
391
|
end
|
362
392
|
|
@@ -0,0 +1,474 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'bolt/config/transport/ssh'
|
4
|
+
require 'bolt/config/transport/winrm'
|
5
|
+
require 'bolt/config/transport/orch'
|
6
|
+
require 'bolt/config/transport/local'
|
7
|
+
require 'bolt/config/transport/docker'
|
8
|
+
require 'bolt/config/transport/remote'
|
9
|
+
|
10
|
+
module Bolt
|
11
|
+
class Config
|
12
|
+
module Options
|
13
|
+
# Transport config classes. Used to load default transport config which
|
14
|
+
# gets passed along to the inventory.
|
15
|
+
TRANSPORT_CONFIG = {
|
16
|
+
'ssh' => Bolt::Config::Transport::SSH,
|
17
|
+
'winrm' => Bolt::Config::Transport::WinRM,
|
18
|
+
'pcp' => Bolt::Config::Transport::Orch,
|
19
|
+
'local' => Bolt::Config::Transport::Local,
|
20
|
+
'docker' => Bolt::Config::Transport::Docker,
|
21
|
+
'remote' => Bolt::Config::Transport::Remote
|
22
|
+
}.freeze
|
23
|
+
|
24
|
+
# Plugin definition. This is used by the JSON schemas to indicate that an option
|
25
|
+
# accepts a plugin reference. Since this isn't used by Bolt to perform automatic
|
26
|
+
# type validation, the :type key is set to a JSON type instead of a Ruby type.
|
27
|
+
PLUGIN = {
|
28
|
+
"_plugin" => {
|
29
|
+
description: "A plugin reference.",
|
30
|
+
type: "object",
|
31
|
+
required: ["_plugin"],
|
32
|
+
properties: {
|
33
|
+
"_plugin" => {
|
34
|
+
description: "The name of the plugin.",
|
35
|
+
type: "string"
|
36
|
+
}
|
37
|
+
}
|
38
|
+
}
|
39
|
+
}.freeze
|
40
|
+
|
41
|
+
# The following constants define the various configuration options available to Bolt.
|
42
|
+
# Each constant is a hash where keys are the configuration option and values are the
|
43
|
+
# option's definition. These options are used in multiple locations:
|
44
|
+
#
|
45
|
+
# - Automatic type validation when loading and setting configuration
|
46
|
+
# - Generating reference documentation for configuration files
|
47
|
+
# - Generating JSON schemas for configuration files
|
48
|
+
#
|
49
|
+
# Data includes keys defined by JSON Schema Draft 07 as well as some metadata used
|
50
|
+
# by Bolt to generate documentation. The following keys are used:
|
51
|
+
#
|
52
|
+
# :description String A detailed description of the option and what it does. This
|
53
|
+
# field is used in both documentation and the JSON schemas,
|
54
|
+
# and should provide as much detail as possible, including
|
55
|
+
# links to relevant documentation.
|
56
|
+
#
|
57
|
+
# :type Class The expected type of a value. These should be Ruby classes,
|
58
|
+
# as this field is used to perform automatic type validation.
|
59
|
+
# If an option can accept more than one type, this should be
|
60
|
+
# an array of types. Boolean values should set :type to
|
61
|
+
# [TrueClass, FalseClass], as Ruby does not have a single
|
62
|
+
# Boolean class.
|
63
|
+
#
|
64
|
+
# :items Hash A definition hash for items in an array. Similar to values
|
65
|
+
# for top-level options, items can have a :description, :type,
|
66
|
+
# or any other key in this list.
|
67
|
+
#
|
68
|
+
# :uniqueItems Boolean Whether or not an array should contain only unique items.
|
69
|
+
#
|
70
|
+
# :properties Hash A hash where keys are sub-options and values are definitions
|
71
|
+
# for the sub-option. Similar to values for top-level options,
|
72
|
+
# properties can have a :description, :type, or any other key
|
73
|
+
# in this list.
|
74
|
+
#
|
75
|
+
# :additionalProperties A variation of the :properties key, where the hash is a
|
76
|
+
# Hash definition for any properties not specified in :properties.
|
77
|
+
# This can be used to permit arbitrary sub-options, such as
|
78
|
+
# logs for the 'log' option.
|
79
|
+
#
|
80
|
+
# :required Array An array of properties that are required for options that
|
81
|
+
# accept Hash values.
|
82
|
+
#
|
83
|
+
# :minimum Integer The minimum integer value for an option.
|
84
|
+
#
|
85
|
+
# :enum Array An array of values that the option recognizes.
|
86
|
+
#
|
87
|
+
# :pattern String A JSON regex pattern that the option's vaue should match.
|
88
|
+
#
|
89
|
+
# :format String Requires that a string value matches a format defined by the
|
90
|
+
# JSON Schema draft.
|
91
|
+
#
|
92
|
+
# :_plugin Boolean Whether the option accepts a plugin reference. This is used
|
93
|
+
# when generating the JSON schemas to determine whether or not
|
94
|
+
# to include a reference to the _plugin definition. If :_plugin
|
95
|
+
# is set to true, the script that generates JSON schemas will
|
96
|
+
# automatically recurse through the :items and :properties keys
|
97
|
+
# and add plugin references if applicable.
|
98
|
+
#
|
99
|
+
# :_example Any An example value for the option. This is used to generate
|
100
|
+
# reference documentation for configuration files.
|
101
|
+
#
|
102
|
+
# :_default Any The documented default value for the option. This is only
|
103
|
+
# used to generate reference documentation for configuration
|
104
|
+
# files and is not used by Bolt to actually set default values.
|
105
|
+
OPTIONS = {
|
106
|
+
"apply_settings" => {
|
107
|
+
description: "A map of Puppet settings to use when applying Puppet code using the `apply` "\
|
108
|
+
"plan function or the `bolt apply` command.",
|
109
|
+
type: Hash,
|
110
|
+
properties: {
|
111
|
+
"show_diff" => {
|
112
|
+
description: "Whether to log and report a contextual diff.",
|
113
|
+
type: [TrueClass, FalseClass],
|
114
|
+
_example: true,
|
115
|
+
_default: false
|
116
|
+
}
|
117
|
+
},
|
118
|
+
_plugin: false
|
119
|
+
},
|
120
|
+
"color" => {
|
121
|
+
description: "Whether to use colored output when printing messages to the console.",
|
122
|
+
type: [TrueClass, FalseClass],
|
123
|
+
_plugin: false,
|
124
|
+
_example: false,
|
125
|
+
_default: true
|
126
|
+
},
|
127
|
+
"compile-concurrency" => {
|
128
|
+
description: "The maximum number of simultaneous manifest block compiles.",
|
129
|
+
type: Integer,
|
130
|
+
minimum: 1,
|
131
|
+
_plugin: false,
|
132
|
+
_example: 5,
|
133
|
+
_default: "Number of cores."
|
134
|
+
},
|
135
|
+
"concurrency" => {
|
136
|
+
description: "The number of threads to use when executing on remote targets.",
|
137
|
+
type: Integer,
|
138
|
+
minimum: 1,
|
139
|
+
_plugin: false,
|
140
|
+
_example: 50,
|
141
|
+
_default: "100 or 1/7 the ulimit, whichever is lower."
|
142
|
+
},
|
143
|
+
"format" => {
|
144
|
+
description: "The format to use when printing results.",
|
145
|
+
type: String,
|
146
|
+
enum: %w[human json rainbow],
|
147
|
+
_plugin: false,
|
148
|
+
_example: "json",
|
149
|
+
_default: "human"
|
150
|
+
},
|
151
|
+
"hiera-config" => {
|
152
|
+
description: "The path to the Hiera configuration file.",
|
153
|
+
type: String,
|
154
|
+
_plugin: false,
|
155
|
+
_example: "~/.puppetlabs/bolt/hiera.yaml",
|
156
|
+
_default: "project/hiera.yaml"
|
157
|
+
},
|
158
|
+
"inventory-config" => {
|
159
|
+
description: "A map of default configuration options for the inventory. This includes options "\
|
160
|
+
"for setting the default transport to use when connecting to targets, as well as "\
|
161
|
+
"options for configuring the default behavior of each transport.",
|
162
|
+
type: Hash,
|
163
|
+
_plugin: false,
|
164
|
+
_example: {}
|
165
|
+
},
|
166
|
+
"inventoryfile" => {
|
167
|
+
description: "The path to a structured data inventory file used to refer to groups of targets on the "\
|
168
|
+
"command line and from plans. Read more about using inventory files in [Inventory "\
|
169
|
+
"files](inventory_file_v2.md).",
|
170
|
+
type: String,
|
171
|
+
_plugin: false,
|
172
|
+
_example: "~/.puppetlabs/bolt/inventory.yaml",
|
173
|
+
_default: "project/inventory.yaml"
|
174
|
+
},
|
175
|
+
"log" => {
|
176
|
+
description: "A map of configuration for the logfile output. Under `log`, you can configure log options "\
|
177
|
+
"for `console` and add configuration for individual log files, such as "\
|
178
|
+
"`~/.puppetlabs/bolt/debug.log`. Individual log files must be valid filepaths. If the log "\
|
179
|
+
"file does not exist, then Bolt will create it before logging information.",
|
180
|
+
type: Hash,
|
181
|
+
properties: {
|
182
|
+
"console" => {
|
183
|
+
description: "Configuration for logs output to the console.",
|
184
|
+
type: Hash,
|
185
|
+
properties: {
|
186
|
+
"level" => {
|
187
|
+
description: "The type of information to log.",
|
188
|
+
type: String,
|
189
|
+
enum: %w[debug error info notice warn fatal any],
|
190
|
+
_default: "warn for console, notice for file"
|
191
|
+
}
|
192
|
+
}
|
193
|
+
}
|
194
|
+
},
|
195
|
+
additionalProperties: {
|
196
|
+
description: "Configuration for the logfile output.",
|
197
|
+
type: Hash,
|
198
|
+
properties: {
|
199
|
+
"append" => {
|
200
|
+
description: "Whether to append output to an existing log file.",
|
201
|
+
type: [TrueClass, FalseClass],
|
202
|
+
_default: true
|
203
|
+
},
|
204
|
+
"level" => {
|
205
|
+
description: "The type of information to log.",
|
206
|
+
type: String,
|
207
|
+
enum: %w[debug error info notice warn fatal any],
|
208
|
+
_default: "warn for console, notice for file"
|
209
|
+
}
|
210
|
+
}
|
211
|
+
},
|
212
|
+
_plugin: false,
|
213
|
+
_example: { "console" => { "level" => "info" },
|
214
|
+
"~/logs/debug.log" => { "append" => false, "level" => "debug" } }
|
215
|
+
},
|
216
|
+
"modulepath" => {
|
217
|
+
description: "An array of directories that Bolt loads content such as plans and tasks from. Read more "\
|
218
|
+
"about modules in [Module structure](module_structure.md).",
|
219
|
+
type: [Array, String],
|
220
|
+
items: {
|
221
|
+
type: String
|
222
|
+
},
|
223
|
+
_plugin: false,
|
224
|
+
_example: ["~/.puppetlabs/bolt/modules", "~/.puppetlabs/bolt/site-modules"],
|
225
|
+
_default: ["project/modules", "project/site-modules", "project/site"]
|
226
|
+
},
|
227
|
+
"name" => {
|
228
|
+
description: "The name of the Bolt project. When this option is configured, the project is considered a "\
|
229
|
+
"[Bolt project](experimental_features.md#bolt-projects), allowing Bolt to load content from "\
|
230
|
+
"the project directory as though it were a module.",
|
231
|
+
type: String,
|
232
|
+
_plugin: false,
|
233
|
+
_example: "myproject"
|
234
|
+
},
|
235
|
+
"plans" => {
|
236
|
+
description: "A list of plan names to show in `bolt plan show` output, if they exist. This option is used "\
|
237
|
+
"to limit the visibility of plans for users of the project. For example, project authors "\
|
238
|
+
"might want to limit the visibility of plans that are bundled with Bolt or plans that should "\
|
239
|
+
"only be run as part of another plan. When this option is not configured, all plans are "\
|
240
|
+
"visible. This option does not prevent users from running plans that are not part of this "\
|
241
|
+
"list.",
|
242
|
+
type: Array,
|
243
|
+
_plugin: false,
|
244
|
+
_example: ["myproject", "myproject::foo", "myproject::bar"]
|
245
|
+
},
|
246
|
+
"plugin_hooks" => {
|
247
|
+
description: "A map of [plugin hooks](writing_plugins.md#hooks) and which plugins a hook should use. "\
|
248
|
+
"The only configurable plugin hook is `puppet_library`, which can use two possible plugins: "\
|
249
|
+
"[`puppet_agent`](https://github.com/puppetlabs/puppetlabs-puppet_agent#puppet_agentinstall) "\
|
250
|
+
"and [`task`](using_plugins.md#task).",
|
251
|
+
type: Hash,
|
252
|
+
_plugin: true,
|
253
|
+
_example: { "puppet_library" => { "plugin" => "puppet_agent", "version" => "6.15.0", "_run_as" => "root" } }
|
254
|
+
},
|
255
|
+
"plugins" => {
|
256
|
+
description: "A map of plugins and their configuration data, where each key is the name of a plugin and "\
|
257
|
+
"its value is a map of configuration data. Configurable options are specified by the plugin. "\
|
258
|
+
"Read more about configuring plugins in [Using plugins](using_plugins.md#configuring-plugins).",
|
259
|
+
type: Hash,
|
260
|
+
_plugin: true,
|
261
|
+
_example: { "pkcs7" => { "keysize" => 1024 } }
|
262
|
+
},
|
263
|
+
"puppetdb" => {
|
264
|
+
description: "A map containing options for [configuring the Bolt PuppetDB "\
|
265
|
+
"client](bolt_connect_puppetdb.md).",
|
266
|
+
type: Hash,
|
267
|
+
properties: {
|
268
|
+
"cacert" => {
|
269
|
+
description: "The path to the ca certificate for PuppetDB.",
|
270
|
+
type: String,
|
271
|
+
_example: "/etc/puppetlabs/puppet/ssl/certs/ca.pem"
|
272
|
+
},
|
273
|
+
"cert" => {
|
274
|
+
description: "The path to the client certificate file to use for authentication.",
|
275
|
+
type: String,
|
276
|
+
_example: "/etc/puppetlabs/puppet/ssl/certs/my-host.example.com.pem"
|
277
|
+
},
|
278
|
+
"key" => {
|
279
|
+
description: "The private key for the certificate.",
|
280
|
+
type: String,
|
281
|
+
_example: "/etc/puppetlabs/puppet/ssl/private_keys/my-host.example.com.pem"
|
282
|
+
},
|
283
|
+
"server_urls" => {
|
284
|
+
description: "An array containing the PuppetDB host to connect to. Include the protocol `https` "\
|
285
|
+
"and the port, which is usually `8081`. For example, "\
|
286
|
+
"`https://my-master.example.com:8081`.",
|
287
|
+
type: Array,
|
288
|
+
_example: ["https://puppet.example.com:8081"]
|
289
|
+
},
|
290
|
+
"token" => {
|
291
|
+
description: "The path to the PE RBAC Token.",
|
292
|
+
type: String,
|
293
|
+
_example: "~/.puppetlabs/token"
|
294
|
+
}
|
295
|
+
},
|
296
|
+
_plugin: true
|
297
|
+
},
|
298
|
+
"puppetfile" => {
|
299
|
+
description: "A map containing options for the `bolt puppetfile install` command.",
|
300
|
+
type: Hash,
|
301
|
+
properties: {
|
302
|
+
"forge" => {
|
303
|
+
description: "A subsection that can have its own `proxy` setting to set an HTTP proxy for Forge "\
|
304
|
+
"operations only, and a `baseurl` setting to specify a different Forge host.",
|
305
|
+
type: Hash,
|
306
|
+
properties: {
|
307
|
+
"baseurl" => {
|
308
|
+
description: "The URL to the Forge host.",
|
309
|
+
type: String,
|
310
|
+
format: "uri",
|
311
|
+
_example: "https://forge.example.com"
|
312
|
+
},
|
313
|
+
"proxy" => {
|
314
|
+
description: "The HTTP proxy to use for Git and Forge operations.",
|
315
|
+
type: String,
|
316
|
+
format: "uri",
|
317
|
+
_example: "https://forgeapi.example.com"
|
318
|
+
}
|
319
|
+
},
|
320
|
+
_example: { "baseurl" => "https://forge.example.com", "proxy" => "https://forgeapi.example.com" }
|
321
|
+
},
|
322
|
+
"proxy" => {
|
323
|
+
description: "The HTTP proxy to use for Git and Forge operations.",
|
324
|
+
type: String,
|
325
|
+
format: "uri",
|
326
|
+
_example: "https://forgeapi.example.com"
|
327
|
+
}
|
328
|
+
},
|
329
|
+
_plugin: false
|
330
|
+
},
|
331
|
+
"save-rerun" => {
|
332
|
+
description: "Whether to update `.rerun.json` in the Bolt project directory. If "\
|
333
|
+
"your target names include passwords, set this value to `false` to avoid "\
|
334
|
+
"writing passwords to disk.",
|
335
|
+
type: [TrueClass, FalseClass],
|
336
|
+
_plugin: false,
|
337
|
+
_example: false,
|
338
|
+
_default: true
|
339
|
+
},
|
340
|
+
"tasks" => {
|
341
|
+
description: "A list of task names to show in `bolt task show` output, if they exist. This option is used "\
|
342
|
+
"to limit the visibility of tasks for users of the project. For example, project authors "\
|
343
|
+
"might want to limit the visibility of tasks that are bundled with Bolt or plans that should "\
|
344
|
+
"only be run as part of a larger workflow. When this option is not configured, all tasks "\
|
345
|
+
"are visible. This option does not prevent users from running tasks that are not part of "\
|
346
|
+
"this list.",
|
347
|
+
type: Array,
|
348
|
+
items: {
|
349
|
+
type: String
|
350
|
+
},
|
351
|
+
_plugin: false,
|
352
|
+
_example: ["myproject", "myproject::foo", "myproject::bar"]
|
353
|
+
},
|
354
|
+
"trusted-external-command" => {
|
355
|
+
description: "The path to an executable on the Bolt controller that can produce external trusted facts. "\
|
356
|
+
"**External trusted facts are experimental in both Puppet and Bolt and this API may change or "\
|
357
|
+
"be removed.**",
|
358
|
+
type: String,
|
359
|
+
_plugin: false,
|
360
|
+
_example: "/etc/puppetlabs/facts/trusted_external.sh"
|
361
|
+
}
|
362
|
+
}.freeze
|
363
|
+
|
364
|
+
# Options that configure the inventory, specifically the default transport
|
365
|
+
# used by targets and the transports themselves. These options are used in
|
366
|
+
# bolt.yaml, under a 'config' key in inventory.yaml, and under the
|
367
|
+
# 'inventory-config' key in bolt-defaults.yaml.
|
368
|
+
INVENTORY_OPTIONS = {
|
369
|
+
"transport" => {
|
370
|
+
description: "The default transport to use when the transport for a target is not "\
|
371
|
+
"specified in the URI.",
|
372
|
+
type: String,
|
373
|
+
enum: TRANSPORT_CONFIG.keys,
|
374
|
+
_plugin: false,
|
375
|
+
_example: "winrm",
|
376
|
+
_default: "ssh"
|
377
|
+
},
|
378
|
+
"docker" => {
|
379
|
+
description: "A map of configuration options for the docker transport.",
|
380
|
+
type: Hash,
|
381
|
+
_plugin: true,
|
382
|
+
_example: { "cleanup" => false, "service-url" => "https://docker.example.com" }
|
383
|
+
},
|
384
|
+
"local" => {
|
385
|
+
description: "A map of configuration options for the local transport. The set of available options is "\
|
386
|
+
"platform dependent.",
|
387
|
+
type: Hash,
|
388
|
+
_plugin: true,
|
389
|
+
_example: { "cleanup" => false, "tmpdir" => "/tmp/bolt" }
|
390
|
+
},
|
391
|
+
"pcp" => {
|
392
|
+
description: "A map of configuration options for the pcp transport.",
|
393
|
+
type: Hash,
|
394
|
+
_plugin: true,
|
395
|
+
_example: { "job-poll-interval" => 15, "job-poll-timeout" => 30 }
|
396
|
+
},
|
397
|
+
"remote" => {
|
398
|
+
description: "A map of configuration options for the remote transport.",
|
399
|
+
type: Hash,
|
400
|
+
_plugin: true,
|
401
|
+
_example: { "run-on" => "proxy_target" }
|
402
|
+
},
|
403
|
+
"ssh" => {
|
404
|
+
description: "A map of configuration options for the ssh transport.",
|
405
|
+
type: Hash,
|
406
|
+
_plugin: true,
|
407
|
+
_example: { "password" => "hunter2!", "user" => "bolt" }
|
408
|
+
},
|
409
|
+
"winrm" => {
|
410
|
+
description: "A map of configuration options for the winrm transport.",
|
411
|
+
type: Hash,
|
412
|
+
_plugin: true,
|
413
|
+
_example: { "password" => "hunter2!", "user" => "bolt" }
|
414
|
+
}
|
415
|
+
}.freeze
|
416
|
+
|
417
|
+
# Options that are available in a bolt.yaml file
|
418
|
+
BOLT_OPTIONS = %w[
|
419
|
+
apply_settings
|
420
|
+
color
|
421
|
+
compile-concurrency
|
422
|
+
concurrency
|
423
|
+
format
|
424
|
+
hiera-config
|
425
|
+
inventoryfile
|
426
|
+
log
|
427
|
+
modulepath
|
428
|
+
plugin_hooks
|
429
|
+
plugins
|
430
|
+
puppetdb
|
431
|
+
puppetfile
|
432
|
+
save-rerun
|
433
|
+
trusted-external-command
|
434
|
+
].freeze
|
435
|
+
|
436
|
+
# Options that are available in a bolt-defaults.yaml file
|
437
|
+
BOLT_DEFAULTS_OPTIONS = %w[
|
438
|
+
color
|
439
|
+
compile-concurrency
|
440
|
+
concurrency
|
441
|
+
format
|
442
|
+
inventory-config
|
443
|
+
log
|
444
|
+
plugin_hooks
|
445
|
+
plugins
|
446
|
+
puppetdb
|
447
|
+
puppetfile
|
448
|
+
save-rerun
|
449
|
+
].freeze
|
450
|
+
|
451
|
+
# Options that are available in a bolt-project.yaml file
|
452
|
+
BOLT_PROJECT_OPTIONS = %w[
|
453
|
+
apply_settings
|
454
|
+
color
|
455
|
+
compile-concurrency
|
456
|
+
concurrency
|
457
|
+
format
|
458
|
+
hiera-config
|
459
|
+
inventoryfile
|
460
|
+
log
|
461
|
+
modulepath
|
462
|
+
name
|
463
|
+
plans
|
464
|
+
plugin_hooks
|
465
|
+
plugins
|
466
|
+
puppetdb
|
467
|
+
puppetfile
|
468
|
+
save-rerun
|
469
|
+
tasks
|
470
|
+
trusted-external-command
|
471
|
+
].freeze
|
472
|
+
end
|
473
|
+
end
|
474
|
+
end
|