bolt 2.12.0 → 2.17.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.

Files changed (78) hide show
  1. checksums.yaml +4 -4
  2. data/Puppetfile +1 -1
  3. data/bolt-modules/boltlib/lib/puppet/datatypes/resourceinstance.rb +3 -2
  4. data/bolt-modules/boltlib/lib/puppet/functions/add_facts.rb +1 -0
  5. data/bolt-modules/boltlib/lib/puppet/functions/add_to_group.rb +1 -0
  6. data/bolt-modules/boltlib/lib/puppet/functions/apply_prep.rb +1 -1
  7. data/bolt-modules/boltlib/lib/puppet/functions/catch_errors.rb +1 -0
  8. data/bolt-modules/boltlib/lib/puppet/functions/facts.rb +1 -0
  9. data/bolt-modules/boltlib/lib/puppet/functions/fail_plan.rb +1 -0
  10. data/bolt-modules/boltlib/lib/puppet/functions/get_resources.rb +2 -1
  11. data/bolt-modules/boltlib/lib/puppet/functions/get_target.rb +1 -0
  12. data/bolt-modules/boltlib/lib/puppet/functions/get_targets.rb +1 -0
  13. data/bolt-modules/boltlib/lib/puppet/functions/puppetdb_fact.rb +1 -0
  14. data/bolt-modules/boltlib/lib/puppet/functions/puppetdb_query.rb +1 -0
  15. data/bolt-modules/boltlib/lib/puppet/functions/remove_from_group.rb +1 -0
  16. data/bolt-modules/boltlib/lib/puppet/functions/resolve_references.rb +1 -0
  17. data/bolt-modules/boltlib/lib/puppet/functions/resource.rb +53 -0
  18. data/bolt-modules/boltlib/lib/puppet/functions/run_command.rb +3 -0
  19. data/bolt-modules/boltlib/lib/puppet/functions/run_plan.rb +7 -2
  20. data/bolt-modules/boltlib/lib/puppet/functions/run_script.rb +7 -4
  21. data/bolt-modules/boltlib/lib/puppet/functions/run_task.rb +6 -3
  22. data/bolt-modules/boltlib/lib/puppet/functions/run_task_with.rb +8 -2
  23. data/bolt-modules/boltlib/lib/puppet/functions/set_config.rb +1 -0
  24. data/bolt-modules/boltlib/lib/puppet/functions/set_feature.rb +1 -0
  25. data/bolt-modules/boltlib/lib/puppet/functions/set_resources.rb +66 -43
  26. data/bolt-modules/boltlib/lib/puppet/functions/set_var.rb +1 -0
  27. data/bolt-modules/boltlib/lib/puppet/functions/upload_file.rb +1 -0
  28. data/bolt-modules/boltlib/lib/puppet/functions/vars.rb +1 -0
  29. data/bolt-modules/boltlib/lib/puppet/functions/wait_until_available.rb +1 -0
  30. data/bolt-modules/boltlib/lib/puppet/functions/without_default_logging.rb +1 -0
  31. data/bolt-modules/boltlib/lib/puppet/functions/write_file.rb +1 -0
  32. data/bolt-modules/ctrl/lib/puppet/functions/ctrl/do_until.rb +2 -0
  33. data/bolt-modules/ctrl/lib/puppet/functions/ctrl/sleep.rb +2 -0
  34. data/bolt-modules/file/lib/puppet/functions/file/exists.rb +2 -1
  35. data/bolt-modules/file/lib/puppet/functions/file/join.rb +2 -0
  36. data/bolt-modules/file/lib/puppet/functions/file/read.rb +3 -1
  37. data/bolt-modules/file/lib/puppet/functions/file/readable.rb +3 -1
  38. data/bolt-modules/file/lib/puppet/functions/file/write.rb +2 -0
  39. data/bolt-modules/out/lib/puppet/functions/out/message.rb +2 -0
  40. data/bolt-modules/prompt/lib/puppet/functions/prompt.rb +1 -0
  41. data/bolt-modules/system/lib/puppet/functions/system/env.rb +2 -0
  42. data/lib/bolt/applicator.rb +20 -7
  43. data/lib/bolt/apply_inventory.rb +4 -0
  44. data/lib/bolt/apply_target.rb +4 -0
  45. data/lib/bolt/bolt_option_parser.rb +20 -13
  46. data/lib/bolt/catalog.rb +81 -68
  47. data/lib/bolt/cli.rb +16 -8
  48. data/lib/bolt/config.rb +150 -138
  49. data/lib/bolt/config/options.rb +473 -0
  50. data/lib/bolt/config/transport/base.rb +16 -16
  51. data/lib/bolt/config/transport/docker.rb +9 -23
  52. data/lib/bolt/config/transport/local.rb +6 -44
  53. data/lib/bolt/config/transport/options.rb +454 -0
  54. data/lib/bolt/config/transport/orch.rb +9 -18
  55. data/lib/bolt/config/transport/remote.rb +3 -6
  56. data/lib/bolt/config/transport/ssh.rb +59 -114
  57. data/lib/bolt/config/transport/winrm.rb +18 -47
  58. data/lib/bolt/executor.rb +14 -1
  59. data/lib/bolt/inventory/group.rb +1 -1
  60. data/lib/bolt/inventory/inventory.rb +4 -14
  61. data/lib/bolt/inventory/target.rb +22 -5
  62. data/lib/bolt/logger.rb +3 -1
  63. data/lib/bolt/outputter.rb +3 -0
  64. data/lib/bolt/outputter/rainbow.rb +84 -0
  65. data/lib/bolt/pal.rb +24 -9
  66. data/lib/bolt/project.rb +64 -55
  67. data/lib/bolt/resource_instance.rb +10 -3
  68. data/lib/bolt/shell/bash.rb +30 -42
  69. data/lib/bolt/shell/powershell.rb +13 -8
  70. data/lib/bolt/shell/powershell/snippets.rb +8 -0
  71. data/lib/bolt/transport/docker.rb +9 -5
  72. data/lib/bolt/transport/local/connection.rb +2 -1
  73. data/lib/bolt/transport/orch.rb +8 -0
  74. data/lib/bolt/transport/ssh/connection.rb +35 -0
  75. data/lib/bolt/version.rb +1 -1
  76. data/lib/bolt_spec/bolt_context.rb +1 -1
  77. data/lib/bolt_spec/run.rb +1 -1
  78. metadata +22 -18
@@ -71,8 +71,10 @@ module Bolt
71
71
  end
72
72
  end
73
73
 
74
- def set_env(arg, val)
75
- "[Environment]::SetEnvironmentVariable('#{arg}', @'\n#{val}\n'@)"
74
+ def env_declarations(env_vars)
75
+ env_vars.map do |var, val|
76
+ "[Environment]::SetEnvironmentVariable('#{var}', @'\n#{val}\n'@)"
77
+ end
76
78
  end
77
79
 
78
80
  def quote_string(string)
@@ -111,7 +113,8 @@ module Bolt
111
113
  end
112
114
 
113
115
  def mkdirs(dirs)
114
- mkdir_command = "mkdir -Force #{dirs.uniq.sort.join(',')}"
116
+ paths = dirs.uniq.sort.join('","')
117
+ mkdir_command = "mkdir -Force -Path (\"#{paths}\")"
115
118
  result = execute(mkdir_command)
116
119
  if result.exit_code != 0
117
120
  message = "Could not create directories: #{result.stderr.string}"
@@ -165,7 +168,9 @@ module Bolt
165
168
  Bolt::Result.for_upload(target, source, destination)
166
169
  end
167
170
 
168
- def run_command(command, _options = {})
171
+ def run_command(command, options = {})
172
+ command = [*env_declarations(options[:env_vars]), command].join("\r\n") if options[:env_vars]
173
+
169
174
  output = execute(command)
170
175
  Bolt::Result.for_command(target,
171
176
  output.stdout.string,
@@ -174,7 +179,7 @@ module Bolt
174
179
  'command', command)
175
180
  end
176
181
 
177
- def run_script(script, arguments, _options = {})
182
+ def run_script(script, arguments, options = {})
178
183
  # unpack any Sensitive data
179
184
  arguments = unwrap_sensitive_args(arguments)
180
185
  with_tmpdir do |dir|
@@ -186,6 +191,8 @@ module Bolt
186
191
  args += escape_arguments(arguments)
187
192
  execute_process(path, args)
188
193
  end
194
+ command = [*env_declarations(options[:env_vars]), command].join("\r\n") if options[:env_vars]
195
+
189
196
  output = execute(command)
190
197
  Bolt::Result.for_command(target,
191
198
  output.stdout.string,
@@ -236,9 +243,7 @@ module Bolt
236
243
  end
237
244
 
238
245
  env_assignments = if Bolt::Task::ENVIRONMENT_METHODS.include?(input_method)
239
- envify_params(arguments).map do |(arg, val)|
240
- set_env(arg, val)
241
- end
246
+ env_declarations(envify_params(arguments))
242
247
  else
243
248
  []
244
249
  end
@@ -20,6 +20,14 @@ module Bolt
20
20
  PS
21
21
  end
22
22
 
23
+ def exit_with_code(command)
24
+ <<~PS
25
+ #{command}
26
+ if (-not $? -and ($LASTEXITCODE -eq $null)) { exit 1 }
27
+ exit $LASTEXITCODE
28
+ PS
29
+ end
30
+
23
31
  def make_tmpdir(parent)
24
32
  <<~PS
25
33
  $parent = #{parent}
@@ -20,7 +20,7 @@ module Bolt
20
20
  def upload(target, source, destination, _options = {})
21
21
  with_connection(target) do |conn|
22
22
  conn.with_remote_tmpdir do |dir|
23
- basename = File.basename(destination)
23
+ basename = File.basename(source)
24
24
  tmpfile = "#{dir}/#{basename}"
25
25
  if File.directory?(source)
26
26
  conn.write_remote_directory(source, tmpfile)
@@ -39,7 +39,9 @@ module Bolt
39
39
  end
40
40
 
41
41
  def run_command(target, command, options = {})
42
- options[:tty] = target.options['tty']
42
+ execute_options = {}
43
+ execute_options[:tty] = target.options['tty']
44
+ execute_options[:environment] = options[:env_vars]
43
45
 
44
46
  if target.options['shell-command'] && !target.options['shell-command'].empty?
45
47
  # escape any double quotes in command
@@ -47,19 +49,21 @@ module Bolt
47
49
  command = "#{target.options['shell-command']} \" #{command}\""
48
50
  end
49
51
  with_connection(target) do |conn|
50
- stdout, stderr, exitcode = conn.execute(*Shellwords.split(command), options)
52
+ stdout, stderr, exitcode = conn.execute(*Shellwords.split(command), execute_options)
51
53
  Bolt::Result.for_command(target, stdout, stderr, exitcode, 'command', command)
52
54
  end
53
55
  end
54
56
 
55
- def run_script(target, script, arguments, _options = {})
57
+ def run_script(target, script, arguments, options = {})
56
58
  # unpack any Sensitive data
57
59
  arguments = unwrap_sensitive_args(arguments)
60
+ execute_options = {}
61
+ execute_options[:environment] = options[:env_vars]
58
62
 
59
63
  with_connection(target) do |conn|
60
64
  conn.with_remote_tmpdir do |dir|
61
65
  remote_path = conn.write_remote_executable(dir, script)
62
- stdout, stderr, exitcode = conn.execute(remote_path, *arguments, {})
66
+ stdout, stderr, exitcode = conn.execute(remote_path, *arguments, execute_options)
63
67
  Bolt::Result.for_command(target, stdout, stderr, exitcode, 'script', script)
64
68
  end
65
69
  end
@@ -50,7 +50,8 @@ module Bolt
50
50
  # If it's already a powershell command then invoke it normally.
51
51
  # Otherwise, wrap it in powershell.exe.
52
52
  unless command.start_with?('powershell.exe')
53
- command = ['powershell.exe', *Bolt::Shell::Powershell::PS_ARGS, '-Command', command]
53
+ cmd = Bolt::Shell::Powershell::Snippets.exit_with_code(command)
54
+ command = ['powershell.exe', *Bolt::Shell::Powershell::PS_ARGS, '-Command', cmd]
54
55
  end
55
56
  end
56
57
 
@@ -82,6 +82,10 @@ module Bolt
82
82
  end
83
83
 
84
84
  def batch_command(targets, command, options = {}, &callback)
85
+ if options[:env_vars] && !options[:env_vars].empty?
86
+ raise NotImplementedError, "pcp transport does not support setting environment variables"
87
+ end
88
+
85
89
  params = {
86
90
  'command' => command
87
91
  }
@@ -98,6 +102,10 @@ module Bolt
98
102
  end
99
103
 
100
104
  def batch_script(targets, script, arguments, options = {}, &callback)
105
+ if options[:env_vars] && !options[:env_vars].empty?
106
+ raise NotImplementedError, "pcp transport does not support setting environment variables"
107
+ end
108
+
101
109
  content = File.open(script, &:read)
102
110
  content = Base64.encode64(content)
103
111
  params = {
@@ -78,6 +78,28 @@ module Bolt
78
78
 
79
79
  options[:proxy] = Net::SSH::Proxy::Jump.new(target.options['proxyjump']) if target.options['proxyjump']
80
80
 
81
+ # Override the default supported algorithms for net-ssh. By default, a subset of supported algorithms
82
+ # are enabled in 6.x, while several are deprecated and not enabled by default. The *-algorithms
83
+ # options can be used to specify a list of algorithms to enable in net-ssh. Any algorithms not in the
84
+ # list are disabled, including ones that are normally enabled by default. Support for deprecated
85
+ # algorithms will be removed in 7.x.
86
+ # https://github.com/net-ssh/net-ssh#supported-algorithms
87
+ if target.options['encryption-algorithms']
88
+ options[:encryption] = net_ssh_algorithms(:encryption, target.options['encryption-algorithms'])
89
+ end
90
+
91
+ if target.options['host-key-algorithms']
92
+ options[:host_key] = net_ssh_algorithms(:host_key, target.options['host-key-algorithms'])
93
+ end
94
+
95
+ if target.options['kex-algorithms']
96
+ options[:kex] = net_ssh_algorithms(:kex, target.options['kex-algorithms'])
97
+ end
98
+
99
+ if target.options['mac-algorithms']
100
+ options[:hmac] = net_ssh_algorithms(:hmac, target.options['mac-algorithms'])
101
+ end
102
+
81
103
  # This option was to address discrepency betwen net-ssh host-key-check and ssh(1)
82
104
  # For the net-ssh 5.x series it defaults to true, in 6.x it will default to false, and will be removed in 7.x
83
105
  # https://github.com/net-ssh/net-ssh/pull/663#issuecomment-469979931
@@ -246,6 +268,19 @@ module Bolt
246
268
  end
247
269
  end
248
270
 
271
+ # Add all default algorithms if the 'defaults' key is present and filter
272
+ # out any unsupported algorithms.
273
+ def net_ssh_algorithms(type, algorithms)
274
+ if algorithms.include?('defaults')
275
+ defaults = Net::SSH::Transport::Algorithms::DEFAULT_ALGORITHMS[type]
276
+ algorithms += defaults
277
+ end
278
+
279
+ known = Net::SSH::Transport::Algorithms::ALGORITHMS[type]
280
+
281
+ algorithms & known
282
+ end
283
+
249
284
  def shell
250
285
  @shell ||= if target.options['login-shell'] == 'powershell'
251
286
  Bolt::Shell::Powershell.new(target, self)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Bolt
4
- VERSION = '2.12.0'
4
+ VERSION = '2.17.0'
5
5
  end
@@ -138,7 +138,7 @@ module BoltSpec
138
138
  # Override in your tests
139
139
  def config
140
140
  @config ||= begin
141
- conf = Bolt::Config.new(Bolt::Project.new('.'), {})
141
+ conf = Bolt::Config.default
142
142
  conf.modulepath = [modulepath].flatten
143
143
  conf
144
144
  end
@@ -144,7 +144,7 @@ module BoltSpec
144
144
  end
145
145
 
146
146
  def config
147
- @config ||= Bolt::Config.new(Bolt::Project.new(@project_path), @config_data)
147
+ @config ||= Bolt::Config.new(Bolt::Project.create_project(@project_path), @config_data)
148
148
  end
149
149
 
150
150
  def inventory
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bolt
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.12.0
4
+ version: 2.17.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Puppet
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-06-01 00:00:00.000000000 Z
11
+ date: 2020-07-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: addressable
@@ -184,7 +184,7 @@ dependencies:
184
184
  requirements:
185
185
  - - ">="
186
186
  - !ruby/object:Gem::Version
187
- version: 6.15.0
187
+ version: 6.16.0
188
188
  - - "<"
189
189
  - !ruby/object:Gem::Version
190
190
  version: '7'
@@ -194,52 +194,52 @@ dependencies:
194
194
  requirements:
195
195
  - - ">="
196
196
  - !ruby/object:Gem::Version
197
- version: 6.15.0
197
+ version: 6.16.0
198
198
  - - "<"
199
199
  - !ruby/object:Gem::Version
200
200
  version: '7'
201
201
  - !ruby/object:Gem::Dependency
202
- name: puppet-resource_api
202
+ name: puppetfile-resolver
203
203
  requirement: !ruby/object:Gem::Requirement
204
204
  requirements:
205
- - - ">="
205
+ - - "~>"
206
206
  - !ruby/object:Gem::Version
207
- version: 1.8.1
207
+ version: 0.1.0
208
208
  type: :runtime
209
209
  prerelease: false
210
210
  version_requirements: !ruby/object:Gem::Requirement
211
211
  requirements:
212
- - - ">="
212
+ - - "~>"
213
213
  - !ruby/object:Gem::Version
214
- version: 1.8.1
214
+ version: 0.1.0
215
215
  - !ruby/object:Gem::Dependency
216
- name: puppet-strings
216
+ name: puppet-resource_api
217
217
  requirement: !ruby/object:Gem::Requirement
218
218
  requirements:
219
- - - "~>"
219
+ - - ">="
220
220
  - !ruby/object:Gem::Version
221
- version: '2.3'
221
+ version: 1.8.1
222
222
  type: :runtime
223
223
  prerelease: false
224
224
  version_requirements: !ruby/object:Gem::Requirement
225
225
  requirements:
226
- - - "~>"
226
+ - - ">="
227
227
  - !ruby/object:Gem::Version
228
- version: '2.3'
228
+ version: 1.8.1
229
229
  - !ruby/object:Gem::Dependency
230
- name: puppetfile-resolver
230
+ name: puppet-strings
231
231
  requirement: !ruby/object:Gem::Requirement
232
232
  requirements:
233
233
  - - "~>"
234
234
  - !ruby/object:Gem::Version
235
- version: 0.1.0
235
+ version: '2.3'
236
236
  type: :runtime
237
237
  prerelease: false
238
238
  version_requirements: !ruby/object:Gem::Requirement
239
239
  requirements:
240
240
  - - "~>"
241
241
  - !ruby/object:Gem::Version
242
- version: 0.1.0
242
+ version: '2.3'
243
243
  - !ruby/object:Gem::Dependency
244
244
  name: r10k
245
245
  requirement: !ruby/object:Gem::Requirement
@@ -407,6 +407,7 @@ files:
407
407
  - bolt-modules/boltlib/lib/puppet/functions/puppetdb_query.rb
408
408
  - bolt-modules/boltlib/lib/puppet/functions/remove_from_group.rb
409
409
  - bolt-modules/boltlib/lib/puppet/functions/resolve_references.rb
410
+ - bolt-modules/boltlib/lib/puppet/functions/resource.rb
410
411
  - bolt-modules/boltlib/lib/puppet/functions/run_command.rb
411
412
  - bolt-modules/boltlib/lib/puppet/functions/run_plan.rb
412
413
  - bolt-modules/boltlib/lib/puppet/functions/run_script.rb
@@ -445,9 +446,11 @@ files:
445
446
  - lib/bolt/catalog/logging.rb
446
447
  - lib/bolt/cli.rb
447
448
  - lib/bolt/config.rb
449
+ - lib/bolt/config/options.rb
448
450
  - lib/bolt/config/transport/base.rb
449
451
  - lib/bolt/config/transport/docker.rb
450
452
  - lib/bolt/config/transport/local.rb
453
+ - lib/bolt/config/transport/options.rb
451
454
  - lib/bolt/config/transport/orch.rb
452
455
  - lib/bolt/config/transport/remote.rb
453
456
  - lib/bolt/config/transport/ssh.rb
@@ -466,6 +469,7 @@ files:
466
469
  - lib/bolt/outputter/human.rb
467
470
  - lib/bolt/outputter/json.rb
468
471
  - lib/bolt/outputter/logger.rb
472
+ - lib/bolt/outputter/rainbow.rb
469
473
  - lib/bolt/pal.rb
470
474
  - lib/bolt/pal/issues.rb
471
475
  - lib/bolt/pal/logging.rb
@@ -588,7 +592,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
588
592
  - !ruby/object:Gem::Version
589
593
  version: '0'
590
594
  requirements: []
591
- rubygems_version: 3.0.6
595
+ rubygems_version: 3.0.8
592
596
  signing_key:
593
597
  specification_version: 4
594
598
  summary: Execute commands remotely over SSH and WinRM