bolt 0.16.2 → 0.16.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ee1bb84782f71c0faea509d91746ce03e9749432
4
- data.tar.gz: 636871a24286b9ca256ffd8c3e31c3224a20ea97
3
+ metadata.gz: 6a4e9a05003d30c06467737a20e98334060a3954
4
+ data.tar.gz: ed19ba7afaab8ea3ff68b2dd5f53bc2830e7b6db
5
5
  SHA512:
6
- metadata.gz: bede0c32f199f41154a2223f74e83c9c7e62a6ea32edadd0850db0bc6faa655603126750e949b1ee2a9192186c527ba3a848205688568bbfcf1bdcb7eab45129
7
- data.tar.gz: b008ffcdd129e7b785a0d93cdb4c37b128d3ab28be930fd7f9e8e5fa40ac5b4250c094be60a2ba12117806c9194029298b6d89df638cc6e945585d9b9b523e0d
6
+ metadata.gz: 6836a6e4a272e4a95e3152b011cfc49af3fd1cc290eaf5660b241b5e2a96784d8b80e0b7c6dcd1ac3bca0452e9b53e10ffe1b1db2b7c9398f34f762f1a50585f
7
+ data.tar.gz: deb82053d48301c05eb9c51eda38232e8baf9f211c720d45c657b91cedf0cce3fdd8fab0cfd3e957ee667e7b18461a4033925b3e3f7fe3a0ba92f6bf460d833d
@@ -100,7 +100,6 @@ HELP
100
100
  'plan' => %w[show run],
101
101
  'file' => %w[upload] }.freeze
102
102
  TRANSPORTS = %w[ssh winrm pcp].freeze
103
- BOLTLIB_PATH = File.join(__FILE__, '../../../modules')
104
103
 
105
104
  attr_reader :parser, :config
106
105
  attr_accessor :options
@@ -3,7 +3,7 @@ require 'bolt/error'
3
3
 
4
4
  module Bolt
5
5
  class PAL
6
- BOLTLIB_PATH = File.join(__FILE__, '../../../modules')
6
+ BOLTLIB_PATH = File.join(__FILE__, '../../../bolt-modules')
7
7
 
8
8
  def initialize(config)
9
9
  # Nothing works without initialized this global state. Reinitializing
@@ -42,12 +42,15 @@ module Bolt
42
42
 
43
43
  def with_events(target, callback)
44
44
  callback.call(type: :node_start, target: target) if callback
45
- result = yield
46
- @logger.debug("Result on #{target.uri}: #{JSON.dump(result.value)}")
45
+
46
+ result = begin
47
+ yield
48
+ rescue StandardError => ex
49
+ Bolt::Result.from_exception(target, ex)
50
+ end
51
+
47
52
  callback.call(type: :node_result, result: result) if callback
48
53
  result
49
- rescue StandardError => ex
50
- Bolt::Result.from_exception(target, ex)
51
54
  end
52
55
 
53
56
  def filter_options(target, options)
@@ -44,7 +44,7 @@ module Bolt
44
44
  conn.write_remote_file(source, tmpfile)
45
45
  # pass over file ownership if we're using run-as to be a different user
46
46
  dir.chown(conn.run_as)
47
- result = conn.execute("mv '#{tmpfile}' '#{destination}'", sudoable: true)
47
+ result = conn.execute(['mv', tmpfile, destination], sudoable: true)
48
48
  if result.exit_code != 0
49
49
  message = "Could not move temporary file '#{tmpfile}' to #{destination}: #{result.stderr.string}"
50
50
  raise Bolt::Node::FileError.new(message, 'MV_ERROR')
@@ -70,7 +70,7 @@ module Bolt
70
70
  conn.with_remote_tempdir do |dir|
71
71
  remote_path = conn.write_remote_executable(dir, script)
72
72
  dir.chown(conn.run_as)
73
- output = conn.execute("'#{remote_path}' #{Shellwords.join(arguments)}", sudoable: true)
73
+ output = conn.execute([remote_path, *arguments], sudoable: true)
74
74
  Bolt::Result.for_command(target, output.stdout.string, output.stderr.string, output.exit_code)
75
75
  end
76
76
  end
@@ -81,31 +81,30 @@ module Bolt
81
81
  input_method = task.input_method
82
82
  with_connection(target) do |conn|
83
83
  conn.running_as(options['_run_as']) do
84
- export_args = {}
85
84
  stdin, output = nil
86
85
 
86
+ command = []
87
+ execute_options = {}
88
+
87
89
  if STDIN_METHODS.include?(input_method)
88
90
  stdin = JSON.dump(arguments)
89
91
  end
90
92
 
91
93
  if ENVIRONMENT_METHODS.include?(input_method)
92
- export_args = arguments.map do |env, val|
93
- "PT_#{env}='#{val}'"
94
- end.join(' ')
94
+ environment = arguments.inject({}) do |env, (param, val)|
95
+ env.merge("PT_#{param}" => val)
96
+ end
97
+ execute_options[:environment] = environment
95
98
  end
96
99
 
97
- command = export_args.empty? ? '' : "#{export_args} "
98
-
99
- execute_options = {}
100
-
101
100
  conn.with_remote_tempdir do |dir|
102
101
  remote_task_path = conn.write_remote_executable(dir, task.executable)
103
102
  if conn.run_as && stdin
104
103
  wrapper = make_wrapper_stringio(remote_task_path, stdin)
105
104
  remote_wrapper_path = conn.write_remote_executable(dir, wrapper, 'wrapper.sh')
106
- command += "'#{remote_wrapper_path}'"
105
+ command << remote_wrapper_path
107
106
  else
108
- command += "'#{remote_task_path}'"
107
+ command << remote_task_path
109
108
  execute_options[:stdin] = stdin
110
109
  end
111
110
  dir.chown(conn.run_as)
@@ -1,4 +1,5 @@
1
1
  require 'logging'
2
+ require 'shellwords'
2
3
  require 'bolt/node/errors'
3
4
  require 'bolt/node/output'
4
5
 
@@ -22,7 +23,7 @@ module Bolt
22
23
  return if owner.nil? || owner == @owner
23
24
 
24
25
  @owner = owner
25
- result = @node.execute("chown -R '#{@owner}': '#{@path}'", sudoable: true, run_as: 'root')
26
+ result = @node.execute(['chown', '-R', "#{@owner}:", @path], sudoable: true, run_as: 'root')
26
27
  if result.exit_code != 0
27
28
  message = "Could not change owner of '#{@path}' to #{@owner}: #{result.stderr.string}"
28
29
  raise Bolt::Node::FileError.new(message, 'CHOWN_ERROR')
@@ -30,7 +31,7 @@ module Bolt
30
31
  end
31
32
 
32
33
  def delete
33
- result = @node.execute("rm -rf '#{@path}'", sudoable: true, run_as: @owner)
34
+ result = @node.execute(['rm', '-rf', @path], sudoable: true, run_as: @owner)
34
35
  if result.exit_code != 0
35
36
  @logger.warn("Failed to clean up tempdir '#{@path}': #{result.stderr.string}")
36
37
  end
@@ -175,20 +176,32 @@ module Bolt
175
176
  result_output = Bolt::Node::Output.new
176
177
  run_as = options[:run_as] || self.run_as
177
178
  use_sudo = sudoable && run_as && @user != run_as
179
+
180
+ command_str = command.is_a?(String) ? command : Shellwords.shelljoin(command)
178
181
  if use_sudo
179
- command = "sudo -S -u #{run_as} -p '#{sudo_prompt}' #{command}"
182
+ sudo_str = Shellwords.shelljoin(["sudo", "-S", "-u", run_as, "-p", sudo_prompt])
183
+ command_str = "#{sudo_str} #{command_str}"
184
+ end
185
+
186
+ # Including the environment declarations in the shelljoin will escape
187
+ # the = sign, so we have to handle them separately.
188
+ if options[:environment]
189
+ env_decls = options[:environment].map do |env, val|
190
+ "#{env}=#{Shellwords.shellescape(val)}"
191
+ end
192
+ command_str = "#{env_decls.join(' ')} #{command_str}"
180
193
  end
181
194
 
182
- @logger.debug { "Executing: #{command}" }
195
+ @logger.debug { "Executing: #{command_str}" }
183
196
 
184
197
  session_channel = @session.open_channel do |channel|
185
198
  # Request a pseudo tty
186
199
  channel.request_pty if target.options[:tty]
187
200
 
188
- channel.exec(command) do |_, success|
201
+ channel.exec(command_str) do |_, success|
189
202
  unless success
190
203
  raise Bolt::Node::ConnectError.new(
191
- "Could not execute command: #{command.inspect}",
204
+ "Could not execute command: #{command_str.inspect}",
192
205
  'EXEC_ERROR'
193
206
  )
194
207
  end
@@ -236,9 +249,9 @@ module Bolt
236
249
  def make_tempdir
237
250
  if target.options[:tmpdir]
238
251
  tmppath = "#{target.options[:tmpdir]}/#{SecureRandom.uuid}"
239
- command = "mkdir -m 700 #{tmppath}"
252
+ command = ['mkdir', '-m', 700, tmppath]
240
253
  else
241
- command = 'mktemp -d'
254
+ command = ['mktemp', '-d']
242
255
  end
243
256
  result = execute(command)
244
257
  if result.exit_code != 0
@@ -266,7 +279,7 @@ module Bolt
266
279
  end
267
280
 
268
281
  def make_executable(path)
269
- result = execute("chmod u+x '#{path}'")
282
+ result = execute(['chmod', 'u+x', path])
270
283
  if result.exit_code != 0
271
284
  message = "Could not make file '#{path}' executable: #{result.stderr.string}"
272
285
  raise Bolt::Node::FileError.new(message, 'CHMOD_ERROR')
@@ -84,7 +84,7 @@ catch
84
84
 
85
85
  if ENVIRONMENT_METHODS.include?(input_method)
86
86
  arguments.each do |(arg, val)|
87
- cmd = "[Environment]::SetEnvironmentVariable('PT_#{arg}', '#{val}')"
87
+ cmd = "[Environment]::SetEnvironmentVariable('PT_#{arg}', @'\n#{val}\n'@)"
88
88
  result = conn.execute(cmd)
89
89
  if result.exit_code != 0
90
90
  raise EnvironmentVarError(var, value)
@@ -1,3 +1,3 @@
1
1
  module Bolt
2
- VERSION = '0.16.2'.freeze
2
+ VERSION = '0.16.3'.freeze
3
3
  end
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: 0.16.2
4
+ version: 0.16.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Puppet
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-02-20 00:00:00.000000000 Z
11
+ date: 2018-02-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: addressable
@@ -332,6 +332,17 @@ executables:
332
332
  extensions: []
333
333
  extra_rdoc_files: []
334
334
  files:
335
+ - bolt-modules/boltlib/lib/puppet/datatypes/result.rb
336
+ - bolt-modules/boltlib/lib/puppet/datatypes/resultset.rb
337
+ - bolt-modules/boltlib/lib/puppet/datatypes/target.rb
338
+ - bolt-modules/boltlib/lib/puppet/functions/fail_plan.rb
339
+ - bolt-modules/boltlib/lib/puppet/functions/file_upload.rb
340
+ - bolt-modules/boltlib/lib/puppet/functions/get_targets.rb
341
+ - bolt-modules/boltlib/lib/puppet/functions/run_command.rb
342
+ - bolt-modules/boltlib/lib/puppet/functions/run_plan.rb
343
+ - bolt-modules/boltlib/lib/puppet/functions/run_script.rb
344
+ - bolt-modules/boltlib/lib/puppet/functions/run_task.rb
345
+ - bolt-modules/boltlib/types/targetspec.pp
335
346
  - exe/bolt
336
347
  - lib/bolt.rb
337
348
  - lib/bolt/cli.rb
@@ -359,17 +370,6 @@ files:
359
370
  - lib/bolt/transport/winrm/connection.rb
360
371
  - lib/bolt/util.rb
361
372
  - lib/bolt/version.rb
362
- - modules/boltlib/lib/puppet/datatypes/result.rb
363
- - modules/boltlib/lib/puppet/datatypes/resultset.rb
364
- - modules/boltlib/lib/puppet/datatypes/target.rb
365
- - modules/boltlib/lib/puppet/functions/fail_plan.rb
366
- - modules/boltlib/lib/puppet/functions/file_upload.rb
367
- - modules/boltlib/lib/puppet/functions/get_targets.rb
368
- - modules/boltlib/lib/puppet/functions/run_command.rb
369
- - modules/boltlib/lib/puppet/functions/run_plan.rb
370
- - modules/boltlib/lib/puppet/functions/run_script.rb
371
- - modules/boltlib/lib/puppet/functions/run_task.rb
372
- - modules/boltlib/types/targetspec.pp
373
373
  - vendored/facter/lib/facter.rb
374
374
  - vendored/facter/lib/facter/Cfkey.rb
375
375
  - vendored/facter/lib/facter/application.rb