bolt 2.21.0 → 2.25.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 (50) hide show
  1. checksums.yaml +4 -4
  2. data/Puppetfile +1 -1
  3. data/bolt-modules/ctrl/lib/puppet/functions/ctrl/do_until.rb +12 -6
  4. data/bolt-modules/out/lib/puppet/functions/out/message.rb +1 -1
  5. data/exe/bolt +1 -0
  6. data/guides/inventory.txt +19 -0
  7. data/guides/project.txt +22 -0
  8. data/lib/bolt/analytics.rb +5 -5
  9. data/lib/bolt/applicator.rb +4 -3
  10. data/lib/bolt/bolt_option_parser.rb +64 -23
  11. data/lib/bolt/catalog.rb +9 -1
  12. data/lib/bolt/cli.rb +218 -73
  13. data/lib/bolt/config.rb +7 -0
  14. data/lib/bolt/config/options.rb +4 -4
  15. data/lib/bolt/executor.rb +9 -7
  16. data/lib/bolt/inventory/group.rb +3 -3
  17. data/lib/bolt/logger.rb +3 -4
  18. data/lib/bolt/module.rb +2 -1
  19. data/lib/bolt/outputter.rb +56 -0
  20. data/lib/bolt/outputter/human.rb +10 -9
  21. data/lib/bolt/outputter/json.rb +11 -4
  22. data/lib/bolt/outputter/logger.rb +2 -2
  23. data/lib/bolt/outputter/rainbow.rb +15 -0
  24. data/lib/bolt/pal.rb +5 -9
  25. data/lib/bolt/pal/yaml_plan/evaluator.rb +1 -1
  26. data/lib/bolt/pal/yaml_plan/transpiler.rb +11 -3
  27. data/lib/bolt/plugin/prompt.rb +3 -3
  28. data/lib/bolt/project.rb +6 -4
  29. data/lib/bolt/project_migrate.rb +138 -0
  30. data/lib/bolt/shell/bash.rb +7 -7
  31. data/lib/bolt/transport/docker/connection.rb +9 -9
  32. data/lib/bolt/transport/local/connection.rb +2 -2
  33. data/lib/bolt/transport/orch.rb +3 -3
  34. data/lib/bolt/transport/ssh/connection.rb +5 -5
  35. data/lib/bolt/transport/ssh/exec_connection.rb +4 -4
  36. data/lib/bolt/transport/winrm/connection.rb +8 -8
  37. data/lib/bolt/util.rb +1 -1
  38. data/lib/bolt/util/puppet_log_level.rb +4 -3
  39. data/lib/bolt/version.rb +1 -1
  40. data/lib/bolt_server/base_config.rb +1 -1
  41. data/lib/bolt_server/pe/pal.rb +1 -1
  42. data/lib/bolt_server/transport_app.rb +76 -0
  43. data/lib/bolt_spec/plans.rb +1 -1
  44. data/lib/bolt_spec/plans/action_stubs.rb +1 -1
  45. data/lib/bolt_spec/run.rb +3 -0
  46. data/libexec/apply_catalog.rb +2 -2
  47. data/libexec/bolt_catalog +1 -1
  48. data/libexec/custom_facts.rb +1 -1
  49. data/libexec/query_resources.rb +1 -1
  50. metadata +7 -4
@@ -4,9 +4,10 @@ module Bolt
4
4
  module Util
5
5
  module PuppetLogLevel
6
6
  MAPPING = {
7
- debug: :debug,
8
- info: :info,
9
- notice: :notice,
7
+ # Demote Puppet's logs by one level, since Puppet is an implementation detail of Bolt
8
+ debug: :trace,
9
+ info: :debug,
10
+ notice: :info,
10
11
  warning: :warn,
11
12
  err: :error,
12
13
  # The following are used by Puppet functions of the same name, and are all treated as
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Bolt
4
- VERSION = '2.21.0'
4
+ VERSION = '2.25.0'
5
5
  end
@@ -16,7 +16,7 @@ module BoltServer
16
16
 
17
17
  def defaults
18
18
  { 'host' => '127.0.0.1',
19
- 'loglevel' => 'notice',
19
+ 'loglevel' => 'warn',
20
20
  'ssl-cipher-suites' => %w[ECDHE-ECDSA-AES256-GCM-SHA384
21
21
  ECDHE-RSA-AES256-GCM-SHA384
22
22
  ECDHE-ECDSA-CHACHA20-POLY1305
@@ -58,7 +58,7 @@ module BoltServer
58
58
  # Bolt::PAL::MODULES_PATH which would be more complex if we tried to use @modulepath since
59
59
  # we need to append our modulepaths and exclude modules shiped in bolt gem code
60
60
  modulepath_dirs = environment.modulepath
61
- @original_modulepath = modulepath_dirs
61
+ @user_modulepath = modulepath_dirs
62
62
  @modulepath = [PE_BOLTLIB_PATH, Bolt::PAL::BOLTLIB_PATH, *modulepath_dirs]
63
63
  end
64
64
  end
@@ -221,6 +221,56 @@ module BoltServer
221
221
  plan_info
222
222
  end
223
223
 
224
+ def build_puppetserver_uri(file_identifier, module_name, environment)
225
+ segments = file_identifier.split('/', 3)
226
+ if segments.size == 1
227
+ {
228
+ 'path' => "/puppet/v3/file_content/tasks/#{module_name}/#{file_identifier}",
229
+ 'params' => {
230
+ 'environment' => environment
231
+ }
232
+ }
233
+ else
234
+ module_segment, mount_segment, name_segment = *segments
235
+ {
236
+ 'path' => case mount_segment
237
+ when 'files'
238
+ "/puppet/v3/file_content/modules/#{module_segment}/#{name_segment}"
239
+ when 'tasks'
240
+ "/puppet/v3/file_content/tasks/#{module_segment}/#{name_segment}"
241
+ when 'lib'
242
+ "/puppet/v3/file_content/plugins/#{name_segment}"
243
+ end,
244
+ 'params' => {
245
+ 'environment' => environment
246
+ }
247
+ }
248
+ end
249
+ end
250
+
251
+ def pe_task_info(pal, module_name, task_name, environment)
252
+ # Handle case where task name is simply module name with special `init` task
253
+ task_name = if task_name == 'init' || task_name.nil?
254
+ module_name
255
+ else
256
+ "#{module_name}::#{task_name}"
257
+ end
258
+ task = pal.get_task(task_name)
259
+ files = task.files.map do |file_hash|
260
+ {
261
+ 'filename' => file_hash['name'],
262
+ 'sha256' => Digest::SHA256.hexdigest(File.read(file_hash['path'])),
263
+ 'size_bytes' => File.size(file_hash['path']),
264
+ 'uri' => build_puppetserver_uri(file_hash['name'], module_name, environment)
265
+ }
266
+ end
267
+ {
268
+ 'metadata' => task.metadata,
269
+ 'name' => task.name,
270
+ 'files' => files
271
+ }
272
+ end
273
+
224
274
  get '/' do
225
275
  200
226
276
  end
@@ -351,6 +401,16 @@ module BoltServer
351
401
  end
352
402
  end
353
403
 
404
+ # Fetches the metadata for a single task
405
+ #
406
+ # @param environment [String] the environment to fetch the task from
407
+ get '/tasks/:module_name/:task_name' do
408
+ in_pe_pal_env(params['environment']) do |pal|
409
+ task_info = pe_task_info(pal, params[:module_name], params[:task_name], params['environment'])
410
+ [200, task_info.to_json]
411
+ end
412
+ end
413
+
354
414
  # Fetches the list of plans for an environment, optionally fetching all metadata for each plan
355
415
  #
356
416
  # @param environment [String] the environment to fetch the list of plans from
@@ -375,6 +435,22 @@ module BoltServer
375
435
  end
376
436
  end
377
437
 
438
+ # Fetches the list of tasks for an environment
439
+ #
440
+ # @param environment [String] the environment to fetch the list of tasks from
441
+ get '/tasks' do
442
+ in_pe_pal_env(params['environment']) do |pal|
443
+ tasks = pal.list_tasks
444
+ tasks_response = tasks.map { |task_name, _description| { 'name' => task_name } }.to_json
445
+
446
+ # We structure this array of tasks to be an array of hashes so that it matches the structure
447
+ # returned by the puppetserver API that serves data like this. Structuring the output this way
448
+ # makes switching between puppetserver and bolt-server easier, which makes changes to switch
449
+ # to bolt-server smaller/simpler.
450
+ [200, tasks_response]
451
+ end
452
+ end
453
+
378
454
  error 404 do
379
455
  err = Bolt::Error.new("Could not find route #{request.path}",
380
456
  'boltserver/not-found')
@@ -206,7 +206,7 @@ module BoltSpec
206
206
  Puppet[:tasks] = true
207
207
 
208
208
  # Ensure logger is initialized with Puppet levels so 'notice' works when running plan specs.
209
- Logging.init :debug, :info, :notice, :warn, :error, :fatal, :any
209
+ Logging.init :trace, :debug, :info, :notice, :warn, :error, :fatal, :any
210
210
  end
211
211
 
212
212
  # Provided as a class so expectations can be placed on it.
@@ -177,7 +177,7 @@ module BoltSpec
177
177
  if data['msg'] && data['kind'] && (data.keys - %w[msg kind details issue_code]).empty?
178
178
  @data[:default] = clazz.new(data['msg'], data['kind'], data['details'], data['issue_code'])
179
179
  else
180
- STDERR.puts "In the future 'error_with()' may require msg and kind, and " \
180
+ $stderr.puts "In the future 'error_with()' may require msg and kind, and " \
181
181
  "optionally accept only details and issue_code."
182
182
  @data[:default] = data
183
183
  end
@@ -8,6 +8,7 @@ require 'bolt/pal'
8
8
  require 'bolt/plugin'
9
9
  require 'bolt/puppetdb'
10
10
  require 'bolt/util'
11
+ require 'bolt/logger'
11
12
 
12
13
  # This is intended to provide a relatively stable method of executing bolt in process from tests.
13
14
  module BoltSpec
@@ -153,6 +154,8 @@ module BoltSpec
153
154
  end
154
155
 
155
156
  def initialize(config_data, inventory_data, project_path)
157
+ Bolt::Logger.initialize_logging
158
+
156
159
  @config_data = config_data || {}
157
160
  @inventory_data = inventory_data || {}
158
161
  @project_path = project_path
@@ -9,7 +9,7 @@ require 'puppet/module_tool/tar'
9
9
  require 'securerandom'
10
10
  require 'tempfile'
11
11
 
12
- args = JSON.parse(ARGV[0] ? File.read(ARGV[0]) : STDIN.read)
12
+ args = JSON.parse(ARGV[0] ? File.read(ARGV[0]) : $stdin.read)
13
13
 
14
14
  # Create temporary directories for all core Puppet settings so we don't clobber
15
15
  # existing state or read from puppet.conf. Also create a temporary modulepath.
@@ -110,7 +110,7 @@ ensure
110
110
  begin
111
111
  FileUtils.remove_dir(puppet_root)
112
112
  rescue Errno::ENOTEMPTY => e
113
- STDERR.puts("Could not cleanup temporary directory: #{e}")
113
+ $stderr.puts("Could not cleanup temporary directory: #{e}")
114
114
  end
115
115
  end
116
116
 
@@ -40,7 +40,7 @@ when "compile"
40
40
  request = if ARGV[1]
41
41
  File.open(ARGV[1]) { |fh| JSON.parse(fh.read) }
42
42
  else
43
- JSON.parse(STDIN.read)
43
+ JSON.parse($stdin.read)
44
44
  end
45
45
  begin
46
46
  catalog = Bolt::Catalog.new.compile_catalog(request)
@@ -6,7 +6,7 @@ require 'puppet'
6
6
  require 'puppet/module_tool/tar'
7
7
  require 'tempfile'
8
8
 
9
- args = JSON.parse(STDIN.read)
9
+ args = JSON.parse($stdin.read)
10
10
 
11
11
  Dir.mktmpdir do |puppet_root|
12
12
  # Create temporary directories for all core Puppet settings so we don't clobber
@@ -6,7 +6,7 @@ require 'puppet'
6
6
  require 'puppet/module_tool/tar'
7
7
  require 'tempfile'
8
8
 
9
- args = JSON.parse(STDIN.read)
9
+ args = JSON.parse($stdin.read)
10
10
 
11
11
  RESOURCE_INSTANCE = /^([^\[]+)\[([^\]]+)\]$/.freeze
12
12
 
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.21.0
4
+ version: 2.25.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-08-03 00:00:00.000000000 Z
11
+ date: 2020-08-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: addressable
@@ -187,7 +187,7 @@ dependencies:
187
187
  version: 6.16.0
188
188
  - - "<"
189
189
  - !ruby/object:Gem::Version
190
- version: '7'
190
+ version: 6.18.0
191
191
  type: :runtime
192
192
  prerelease: false
193
193
  version_requirements: !ruby/object:Gem::Requirement
@@ -197,7 +197,7 @@ dependencies:
197
197
  version: 6.16.0
198
198
  - - "<"
199
199
  - !ruby/object:Gem::Version
200
- version: '7'
200
+ version: 6.18.0
201
201
  - !ruby/object:Gem::Dependency
202
202
  name: puppetfile-resolver
203
203
  requirement: !ruby/object:Gem::Requirement
@@ -437,6 +437,8 @@ files:
437
437
  - bolt-modules/prompt/lib/puppet/functions/prompt.rb
438
438
  - bolt-modules/system/lib/puppet/functions/system/env.rb
439
439
  - exe/bolt
440
+ - guides/inventory.txt
441
+ - guides/project.txt
440
442
  - lib/bolt.rb
441
443
  - lib/bolt/analytics.rb
442
444
  - lib/bolt/applicator.rb
@@ -498,6 +500,7 @@ files:
498
500
  - lib/bolt/plugin/puppetdb.rb
499
501
  - lib/bolt/plugin/task.rb
500
502
  - lib/bolt/project.rb
503
+ - lib/bolt/project_migrate.rb
501
504
  - lib/bolt/puppetdb.rb
502
505
  - lib/bolt/puppetdb/client.rb
503
506
  - lib/bolt/puppetdb/config.rb