bolt 0.17.2 → 0.18.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 (55) hide show
  1. checksums.yaml +4 -4
  2. data/bolt-modules/boltlib/lib/puppet/datatypes/result.rb +2 -0
  3. data/bolt-modules/boltlib/lib/puppet/datatypes/resultset.rb +2 -0
  4. data/bolt-modules/boltlib/lib/puppet/datatypes/target.rb +2 -0
  5. data/bolt-modules/boltlib/lib/puppet/functions/add_facts.rb +30 -0
  6. data/bolt-modules/boltlib/lib/puppet/functions/facts.rb +30 -0
  7. data/bolt-modules/boltlib/lib/puppet/functions/fail_plan.rb +4 -2
  8. data/bolt-modules/boltlib/lib/puppet/functions/file_upload.rb +2 -0
  9. data/bolt-modules/boltlib/lib/puppet/functions/get_targets.rb +2 -0
  10. data/bolt-modules/boltlib/lib/puppet/functions/run_command.rb +2 -0
  11. data/bolt-modules/boltlib/lib/puppet/functions/run_plan.rb +3 -2
  12. data/bolt-modules/boltlib/lib/puppet/functions/run_script.rb +2 -1
  13. data/bolt-modules/boltlib/lib/puppet/functions/run_task.rb +2 -0
  14. data/bolt-modules/boltlib/lib/puppet/functions/set_var.rb +8 -0
  15. data/bolt-modules/boltlib/lib/puppet/functions/vars.rb +9 -1
  16. data/exe/bolt +1 -0
  17. data/exe/bolt-inventory-pdb +1 -0
  18. data/lib/bolt.rb +2 -0
  19. data/lib/bolt/cli.rb +40 -34
  20. data/lib/bolt/config.rb +9 -2
  21. data/lib/bolt/error.rb +2 -0
  22. data/lib/bolt/executor.rb +2 -0
  23. data/lib/bolt/inventory.rb +36 -28
  24. data/lib/bolt/inventory/group.rb +14 -10
  25. data/lib/bolt/logger.rb +2 -0
  26. data/lib/bolt/node/errors.rb +2 -0
  27. data/lib/bolt/node/output.rb +2 -0
  28. data/lib/bolt/notifier.rb +2 -0
  29. data/lib/bolt/outputter.rb +2 -0
  30. data/lib/bolt/outputter/human.rb +28 -34
  31. data/lib/bolt/outputter/json.rb +7 -5
  32. data/lib/bolt/pal.rb +66 -30
  33. data/lib/bolt/puppetdb.rb +2 -0
  34. data/lib/bolt/puppetdb/client.rb +5 -3
  35. data/lib/bolt/puppetdb/config.rb +2 -0
  36. data/lib/bolt/result.rb +2 -0
  37. data/lib/bolt/result_set.rb +2 -0
  38. data/lib/bolt/target.rb +2 -0
  39. data/lib/bolt/transport/base.rb +4 -2
  40. data/lib/bolt/transport/local.rb +2 -0
  41. data/lib/bolt/transport/local/shell.rb +2 -0
  42. data/lib/bolt/transport/orch.rb +3 -1
  43. data/lib/bolt/transport/ssh.rb +3 -1
  44. data/lib/bolt/transport/ssh/connection.rb +3 -1
  45. data/lib/bolt/transport/winrm.rb +9 -2
  46. data/lib/bolt/transport/winrm/connection.rb +11 -3
  47. data/lib/bolt/util.rb +9 -7
  48. data/lib/bolt/version.rb +3 -1
  49. data/lib/bolt_ext/puppetdb_inventory.rb +3 -2
  50. data/modules/aggregate/lib/puppet/functions/aggregate/count.rb +2 -0
  51. data/modules/aggregate/lib/puppet/functions/aggregate/nodes.rb +2 -0
  52. data/modules/canary/lib/puppet/functions/canary/merge.rb +2 -0
  53. data/modules/canary/lib/puppet/functions/canary/random_split.rb +2 -0
  54. data/modules/canary/lib/puppet/functions/canary/skip.rb +2 -0
  55. metadata +37 -35
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'bolt/error'
2
4
  require 'bolt/puppetdb/client'
3
5
  require 'bolt/puppetdb/config'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'json'
2
4
  require 'uri'
3
5
  require 'httpclient'
@@ -41,11 +43,11 @@ module Bolt
41
43
  raise Bolt::PuppetDBError, "Failed to query PuppetDB: #{response.body}"
42
44
  else
43
45
  results = JSON.parse(response.body)
44
- if results.first && !results.first.key?('certname')
45
- fields = results.first.keys
46
+ if results&.first && !results.first&.key?('certname')
47
+ fields = results.first&.keys
46
48
  raise Bolt::PuppetDBError, "Query results did not contain a 'certname' field: got #{fields.join(', ')}"
47
49
  end
48
- results.map { |result| result['certname'] }.uniq
50
+ results&.map { |result| result['certname'] }.uniq
49
51
  end
50
52
  end
51
53
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'json'
2
4
 
3
5
  module Bolt
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'json'
2
4
  require 'bolt/error'
3
5
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Bolt
2
4
  class ResultSet
3
5
  attr_reader :results
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'addressable/uri'
2
4
  require 'bolt/error'
3
5
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'logging'
2
4
 
3
5
  module Bolt
@@ -53,7 +55,7 @@ module Bolt
53
55
  end
54
56
 
55
57
  def with_events(target, callback)
56
- callback.call(type: :node_start, target: target) if callback
58
+ callback&.call(type: :node_start, target: target)
57
59
 
58
60
  result = begin
59
61
  yield
@@ -61,7 +63,7 @@ module Bolt
61
63
  Bolt::Result.from_exception(target, ex)
62
64
  end
63
65
 
64
- callback.call(type: :node_result, result: result) if callback
66
+ callback&.call(type: :node_result, result: result)
65
67
  result
66
68
  end
67
69
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'json'
2
4
  require 'fileutils'
3
5
  require 'tmpdir'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'open3'
2
4
  require 'bolt/node/output'
3
5
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'base64'
2
4
  require 'concurrent'
3
5
  require 'json'
@@ -122,7 +124,7 @@ module Bolt
122
124
  end
123
125
  end
124
126
  results.each do |result|
125
- callback.call(type: :node_result, result: result) if callback
127
+ callback&.call(type: :node_result, result: result)
126
128
  end
127
129
  end
128
130
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'bolt/node/errors'
2
4
  require 'bolt/transport/base'
3
5
  require 'json'
@@ -57,7 +59,7 @@ module Bolt
57
59
  yield conn
58
60
  ensure
59
61
  begin
60
- conn.disconnect if conn
62
+ conn&.disconnect
61
63
  rescue StandardError => ex
62
64
  logger.info("Failed to close connection to #{target.uri} : #{ex.message}")
63
65
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'logging'
2
4
  require 'shellwords'
3
5
  require 'bolt/node/errors'
@@ -274,7 +276,7 @@ module Bolt
274
276
  dir = make_tempdir
275
277
  yield dir
276
278
  ensure
277
- dir.delete if dir
279
+ dir&.delete
278
280
  end
279
281
 
280
282
  def write_remote_executable(dir, file, filename = nil)
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'bolt/transport/base'
2
4
 
3
5
  module Bolt
@@ -8,7 +10,7 @@ module Bolt
8
10
  ].freeze
9
11
 
10
12
  def self.options
11
- %w[port user password connect-timeout ssl tmpdir cacert extensions]
13
+ %w[port user password connect-timeout ssl ssl-verify tmpdir cacert extensions]
12
14
  end
13
15
 
14
16
  def self.validate(options)
@@ -17,6 +19,11 @@ module Bolt
17
19
  raise Bolt::CLIError, 'ssl option must be a Boolean true or false'
18
20
  end
19
21
 
22
+ ssl_verify_flag = options['ssl-verify']
23
+ unless !!ssl_verify_flag == ssl_verify_flag
24
+ raise Bolt::CLIError, 'ssl-verify option must be a Boolean true or false'
25
+ end
26
+
20
27
  timeout_value = options['connect-timeout']
21
28
  unless timeout_value.is_a?(Integer) || timeout_value.nil?
22
29
  error_msg = "connect-timeout value must be an Integer, received #{timeout_value}:#{timeout_value.class}"
@@ -36,7 +43,7 @@ module Bolt
36
43
  yield conn
37
44
  ensure
38
45
  begin
39
- conn.disconnect if conn
46
+ conn&.disconnect
40
47
  rescue StandardError => ex
41
48
  logger.info("Failed to close connection to #{target.uri} : #{ex.message}")
42
49
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'bolt/node/errors'
2
4
  require 'bolt/node/output'
3
5
 
@@ -40,7 +42,8 @@ module Bolt
40
42
  password: target.password,
41
43
  retry_limit: 1,
42
44
  transport: transport,
43
- ca_trust_path: target.options['cacert'] }
45
+ ca_trust_path: target.options['cacert'],
46
+ no_ssl_peer_verification: !target.options['ssl-verify'] }
44
47
 
45
48
  Timeout.timeout(target.options['connect-timeout']) do
46
49
  @connection = ::WinRM::Connection.new(options)
@@ -72,6 +75,11 @@ module Bolt
72
75
  if target.options['ssl'] && @port == HTTP_PORT
73
76
  theres_your_problem = "\nAre you using SSL to connect to a non-SSL port?"
74
77
  end
78
+ if target.options['ssl-verify'] && e.message.include?('certificate verify failed')
79
+ theres_your_problem = "\nIs the remote host using a self-signed SSL"\
80
+ "certificate? Use --no-ssl-verify to disable "\
81
+ "remote host SSL verification."
82
+ end
75
83
  raise Bolt::Node::ConnectError.new(
76
84
  "Failed to connect to #{endpoint}: #{e.message}#{theres_your_problem}",
77
85
  "CONNECT_ERROR"
@@ -84,7 +92,7 @@ module Bolt
84
92
  end
85
93
 
86
94
  def disconnect
87
- @session.close if @session
95
+ @session&.close
88
96
  @logger.debug { "Closed session" }
89
97
  end
90
98
 
@@ -377,7 +385,7 @@ PS
377
385
  @shell_initialized = true
378
386
  end
379
387
 
380
- def execute(command, _ = {})
388
+ def execute(command)
381
389
  result_output = Bolt::Node::Output.new
382
390
 
383
391
  @logger.debug { "Executing command: #{command}" }
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Bolt
2
4
  module Util
3
5
  # CODEREVIEW I hate mixing in random modules
@@ -15,17 +17,11 @@ module Bolt
15
17
  end
16
18
 
17
19
  path = File.expand_path(path)
18
- # safe_load doesn't work with psych in ruby 2.0
19
- # The user controls the configfile so this isn't a problem
20
- # rubocop:disable YAMLLoad
21
- File.open(path, "r:UTF-8") { |f| YAML.load(f.read) }
20
+ File.open(path, "r:UTF-8") { |f| YAML.safe_load(f.read) }
22
21
  rescue Errno::ENOENT
23
22
  if path_passed
24
23
  raise Bolt::CLIError, "Could not read #{file_name} file: #{path}"
25
24
  end
26
- # In older releases of psych SyntaxError is not a subclass of Exception
27
- rescue Psych::SyntaxError
28
- raise Bolt::CLIError, "Could not parse #{file_name} file: #{path}"
29
25
  rescue Psych::Exception
30
26
  raise Bolt::CLIError, "Could not parse #{file_name} file: #{path}"
31
27
  rescue IOError, SystemCallError
@@ -43,6 +39,12 @@ module Bolt
43
39
  hash1.merge(hash2, &recursive_merge)
44
40
  end
45
41
 
42
+ def map_vals(hash)
43
+ hash.each_with_object({}) do |(k, v), acc|
44
+ acc[k] = yield(v)
45
+ end
46
+ end
47
+
46
48
  # Accepts a Data object and returns a copy with all hash keys
47
49
  # modifed by block. use &:to_s to stringify keys or :to_sym to symbolize them
48
50
  def walk_keys(data, &block)
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Bolt
2
- VERSION = '0.17.2'.freeze
4
+ VERSION = '0.18.0'
3
5
  end
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
4
  require 'bolt/puppetdb/config'
4
5
  require 'json'
@@ -99,11 +100,11 @@ query results.
99
100
  puts result
100
101
  end
101
102
 
102
- return 0
103
+ 0
103
104
  rescue StandardError => e
104
105
  puts "Error: #{e}"
105
106
  puts e.backtrace if @trace
106
- return 1
107
+ 1
107
108
  end
108
109
 
109
110
  def resolve_group(group)
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # Aggregates the key/value pairs in the results of a ResultSet into a hash
2
4
  # mapping the keys to a hash of each distinct value and how many nodes returned
3
5
  # that value for the key.
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # Aggregates the key/value pairs in the results of a ResultSet into a hash
2
4
  # mapping the keys to a hash of each distinct value and the list of nodes
3
5
  # returning that value for the key.
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # Merges two ResultSets into a new ResultSet
2
4
  Puppet::Functions.create_function(:'canary::merge') do
3
5
  dispatch :merge_results do
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # Splits an array into two groups, where the 1st group is a randomly selected
2
4
  # sample of the input (of the specified size) and the 2nd group is the remainder.
3
5
  #
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # Returns a ResultSet with canary/skipped-node errors for each Target provided.
2
4
  #
3
5
  # This function takes a single parameter:
metadata CHANGED
@@ -1,29 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bolt
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.17.2
4
+ version: 0.18.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Puppet
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-03-14 00:00:00.000000000 Z
11
+ date: 2018-03-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: addressable
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "<"
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 2.5.0
19
+ version: '2.5'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "<"
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 2.5.0
26
+ version: '2.5'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: concurrent-ruby
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '1.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: logging
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '2.2'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '2.2'
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: net-scp
43
57
  requirement: !ruby/object:Gem::Requirement
@@ -72,28 +86,28 @@ dependencies:
72
86
  requirements:
73
87
  - - "~>"
74
88
  - !ruby/object:Gem::Version
75
- version: 0.2.3
89
+ version: '0.2'
76
90
  type: :runtime
77
91
  prerelease: false
78
92
  version_requirements: !ruby/object:Gem::Requirement
79
93
  requirements:
80
94
  - - "~>"
81
95
  - !ruby/object:Gem::Version
82
- version: 0.2.3
96
+ version: '0.2'
83
97
  - !ruby/object:Gem::Dependency
84
98
  name: terminal-table
85
99
  requirement: !ruby/object:Gem::Requirement
86
100
  requirements:
87
101
  - - "~>"
88
102
  - !ruby/object:Gem::Version
89
- version: 1.8.0
103
+ version: '1.8'
90
104
  type: :runtime
91
105
  prerelease: false
92
106
  version_requirements: !ruby/object:Gem::Requirement
93
107
  requirements:
94
108
  - - "~>"
95
109
  - !ruby/object:Gem::Version
96
- version: 1.8.0
110
+ version: '1.8'
97
111
  - !ruby/object:Gem::Dependency
98
112
  name: winrm
99
113
  requirement: !ruby/object:Gem::Requirement
@@ -114,28 +128,14 @@ dependencies:
114
128
  requirements:
115
129
  - - "~>"
116
130
  - !ruby/object:Gem::Version
117
- version: 1.1.0
118
- type: :runtime
119
- prerelease: false
120
- version_requirements: !ruby/object:Gem::Requirement
121
- requirements:
122
- - - "~>"
123
- - !ruby/object:Gem::Version
124
- version: 1.1.0
125
- - !ruby/object:Gem::Dependency
126
- name: logging
127
- requirement: !ruby/object:Gem::Requirement
128
- requirements:
129
- - - "~>"
130
- - !ruby/object:Gem::Version
131
- version: '2.2'
131
+ version: '1.1'
132
132
  type: :runtime
133
133
  prerelease: false
134
134
  version_requirements: !ruby/object:Gem::Requirement
135
135
  requirements:
136
136
  - - "~>"
137
137
  - !ruby/object:Gem::Version
138
- version: '2.2'
138
+ version: '1.1'
139
139
  - !ruby/object:Gem::Dependency
140
140
  name: CFPropertyList
141
141
  requirement: !ruby/object:Gem::Requirement
@@ -190,14 +190,14 @@ dependencies:
190
190
  requirements:
191
191
  - - "~>"
192
192
  - !ruby/object:Gem::Version
193
- version: 0.6.1
193
+ version: '0.6'
194
194
  type: :runtime
195
195
  prerelease: false
196
196
  version_requirements: !ruby/object:Gem::Requirement
197
197
  requirements:
198
198
  - - "~>"
199
199
  - !ruby/object:Gem::Version
200
- version: 0.6.1
200
+ version: '0.6'
201
201
  - !ruby/object:Gem::Dependency
202
202
  name: win32-dir
203
203
  requirement: !ruby/object:Gem::Requirement
@@ -255,33 +255,33 @@ dependencies:
255
255
  - !ruby/object:Gem::Version
256
256
  version: 0.8.8
257
257
  - !ruby/object:Gem::Dependency
258
- name: puppetlabs_spec_helper
258
+ name: bundler
259
259
  requirement: !ruby/object:Gem::Requirement
260
260
  requirements:
261
261
  - - "~>"
262
262
  - !ruby/object:Gem::Version
263
- version: '2.6'
263
+ version: '1.14'
264
264
  type: :development
265
265
  prerelease: false
266
266
  version_requirements: !ruby/object:Gem::Requirement
267
267
  requirements:
268
268
  - - "~>"
269
269
  - !ruby/object:Gem::Version
270
- version: '2.6'
270
+ version: '1.14'
271
271
  - !ruby/object:Gem::Dependency
272
- name: bundler
272
+ name: puppetlabs_spec_helper
273
273
  requirement: !ruby/object:Gem::Requirement
274
274
  requirements:
275
275
  - - "~>"
276
276
  - !ruby/object:Gem::Version
277
- version: '1.14'
277
+ version: '2.6'
278
278
  type: :development
279
279
  prerelease: false
280
280
  version_requirements: !ruby/object:Gem::Requirement
281
281
  requirements:
282
282
  - - "~>"
283
283
  - !ruby/object:Gem::Version
284
- version: '1.14'
284
+ version: '2.6'
285
285
  - !ruby/object:Gem::Dependency
286
286
  name: rake
287
287
  requirement: !ruby/object:Gem::Requirement
@@ -322,6 +322,8 @@ files:
322
322
  - bolt-modules/boltlib/lib/puppet/datatypes/result.rb
323
323
  - bolt-modules/boltlib/lib/puppet/datatypes/resultset.rb
324
324
  - bolt-modules/boltlib/lib/puppet/datatypes/target.rb
325
+ - bolt-modules/boltlib/lib/puppet/functions/add_facts.rb
326
+ - bolt-modules/boltlib/lib/puppet/functions/facts.rb
325
327
  - bolt-modules/boltlib/lib/puppet/functions/fail_plan.rb
326
328
  - bolt-modules/boltlib/lib/puppet/functions/file_upload.rb
327
329
  - bolt-modules/boltlib/lib/puppet/functions/get_targets.rb
@@ -1622,7 +1624,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
1622
1624
  requirements:
1623
1625
  - - "~>"
1624
1626
  - !ruby/object:Gem::Version
1625
- version: '2.0'
1627
+ version: '2.3'
1626
1628
  required_rubygems_version: !ruby/object:Gem::Requirement
1627
1629
  requirements:
1628
1630
  - - ">="