bolt 2.35.0 → 2.36.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 (36) hide show
  1. checksums.yaml +4 -4
  2. data/bolt-modules/boltlib/lib/puppet/datatypes/applyresult.rb +1 -0
  3. data/lib/bolt/analytics.rb +27 -8
  4. data/lib/bolt/apply_result.rb +3 -3
  5. data/lib/bolt/bolt_option_parser.rb +38 -15
  6. data/lib/bolt/cli.rb +13 -87
  7. data/lib/bolt/config.rb +131 -52
  8. data/lib/bolt/config/options.rb +42 -4
  9. data/lib/bolt/config/transport/base.rb +10 -19
  10. data/lib/bolt/config/transport/local.rb +0 -7
  11. data/lib/bolt/config/transport/ssh.rb +8 -14
  12. data/lib/bolt/config/validator.rb +231 -0
  13. data/lib/bolt/executor.rb +5 -17
  14. data/lib/bolt/outputter/rainbow.rb +1 -1
  15. data/lib/bolt/plugin.rb +0 -7
  16. data/lib/bolt/project.rb +30 -36
  17. data/lib/bolt/project_manager.rb +199 -0
  18. data/lib/bolt/{project_migrator/config.rb → project_manager/config_migrator.rb} +41 -4
  19. data/lib/bolt/{project_migrator/inventory.rb → project_manager/inventory_migrator.rb} +3 -3
  20. data/lib/bolt/{project_migrator/base.rb → project_manager/migrator.rb} +2 -2
  21. data/lib/bolt/{project_migrator/modules.rb → project_manager/module_migrator.rb} +3 -3
  22. data/lib/bolt/puppetdb/config.rb +1 -2
  23. data/lib/bolt/shell/bash.rb +1 -1
  24. data/lib/bolt/task/run.rb +1 -1
  25. data/lib/bolt/transport/ssh/exec_connection.rb +6 -2
  26. data/lib/bolt/util.rb +14 -7
  27. data/lib/bolt/version.rb +1 -1
  28. data/lib/bolt_server/base_config.rb +3 -1
  29. data/lib/bolt_server/config.rb +3 -1
  30. data/lib/bolt_server/schemas/partials/task.json +2 -2
  31. data/lib/bolt_server/transport_app.rb +5 -5
  32. data/libexec/apply_catalog.rb +1 -1
  33. data/libexec/custom_facts.rb +1 -1
  34. data/libexec/query_resources.rb +1 -1
  35. metadata +8 -13
  36. data/lib/bolt/project_migrator.rb +0 -80
@@ -4,8 +4,8 @@ require 'fileutils'
4
4
  require 'bolt/error'
5
5
 
6
6
  module Bolt
7
- class ProjectMigrator
8
- class Base
7
+ class ProjectManager
8
+ class Migrator
9
9
  def initialize(outputter)
10
10
  @outputter = outputter
11
11
  end
@@ -1,10 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'bolt/project_migrator/base'
3
+ require 'bolt/project_manager/migrator'
4
4
 
5
5
  module Bolt
6
- class ProjectMigrator
7
- class Modules < Base
6
+ class ProjectManager
7
+ class ModuleMigrator < Migrator
8
8
  def migrate(project, configured_modulepath)
9
9
  return true unless project.modules.nil?
10
10
 
@@ -18,8 +18,7 @@ module Bolt
18
18
  end
19
19
 
20
20
  def self.default_windows_config
21
- require 'win32/dir'
22
- File.expand_path(File.join(Dir::COMMON_APPDATA, 'PuppetLabs/client-tools/puppetdb.conf'))
21
+ File.expand_path(File.join(ENV['ALLUSERSPROFILE'], 'PuppetLabs/client-tools/puppetdb.conf'))
23
22
  end
24
23
 
25
24
  def self.load_config(options, project_path = nil)
@@ -199,7 +199,7 @@ module Bolt
199
199
  lines = buffer.split(/(?<=\n)/)
200
200
  # handle_sudo will return the line if it is not a sudo prompt or error
201
201
  lines.map! { |line| handle_sudo(inp, line, stdin) }
202
- lines.join("")
202
+ lines.join
203
203
  # If stream has reached EOF, no password prompt is expected
204
204
  # return an empty string
205
205
  rescue EOFError
@@ -42,7 +42,7 @@ module Bolt
42
42
  if targets.empty?
43
43
  Bolt::ResultSet.new([])
44
44
  else
45
- result = executor.run_task_with_minimal_logging(targets, task, params, options)
45
+ result = executor.run_task(targets, task, params, options, [], :trace)
46
46
 
47
47
  if !result.ok && !options[:catch_errors]
48
48
  raise Bolt::RunFailure.new(result, 'run_task', task.name)
@@ -12,8 +12,12 @@ module Bolt
12
12
  raise Bolt::ValidationError, "Target #{target.safe_name} does not have a host" unless target.host
13
13
 
14
14
  @target = target
15
- ssh_config = Net::SSH::Config.for(target.host)
16
- @user = @target.user || ssh_config[:user] || Etc.getlogin
15
+ begin
16
+ ssh_config = Net::SSH::Config.for(target.host)
17
+ @user = @target.user || ssh_config[:user] || Etc.getlogin
18
+ rescue StandardError
19
+ @user = @target.user || Etc.getlogin
20
+ end
17
21
  @logger = Bolt::Logger.logger(self)
18
22
  end
19
23
 
@@ -29,19 +29,26 @@ module Bolt
29
29
  path = File.expand_path(path)
30
30
  content = File.open(path, "r:UTF-8") { |f| YAML.safe_load(f.read) } || {}
31
31
  unless content.is_a?(Hash)
32
- msg = "Invalid content for #{file_name} file: #{path} should be a Hash or empty, not #{content.class}"
33
- raise Bolt::FileError.new(msg, path)
32
+ raise Bolt::FileError.new(
33
+ "Invalid content for #{file_name} file at #{path}\nContent should be a Hash or empty, "\
34
+ "not #{content.class}",
35
+ path
36
+ )
34
37
  end
35
38
  logger.trace("Loaded #{file_name} from #{path}")
36
39
  content
37
40
  rescue Errno::ENOENT
38
- raise Bolt::FileError.new("Could not read #{file_name} file: #{path}", path)
41
+ raise Bolt::FileError.new("Could not read #{file_name} file at #{path}", path)
42
+ rescue Psych::SyntaxError => e
43
+ raise Bolt::FileError.new("Could not parse #{file_name} file at #{path}, line #{e.line}, "\
44
+ "column #{e.column}\n#{e.problem}",
45
+ path)
39
46
  rescue Psych::Exception => e
40
- raise Bolt::FileError.new("Could not parse #{file_name} file: #{path}\n"\
41
- "Error at line #{e.line} column #{e.column}", path)
47
+ raise Bolt::FileError.new("Could not parse #{file_name} file at #{path}\n#{e.message}",
48
+ path)
42
49
  rescue IOError, SystemCallError => e
43
- raise Bolt::FileError.new("Could not read #{file_name} file: #{path}\n"\
44
- "error: #{e}", path)
50
+ raise Bolt::FileError.new("Could not read #{file_name} file at #{path}\n#{e.message}",
51
+ path)
45
52
  end
46
53
 
47
54
  def read_optional_yaml_hash(path, file_name)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Bolt
4
- VERSION = '2.35.0'
4
+ VERSION = '2.36.0'
5
5
  end
@@ -7,7 +7,9 @@ module BoltServer
7
7
  class BaseConfig
8
8
  def config_keys
9
9
  %w[host port ssl-cert ssl-key ssl-ca-cert
10
- ssl-cipher-suites loglevel logfile allowlist projects-dir]
10
+ ssl-cipher-suites loglevel logfile allowlist
11
+ projects-dir environments-codedir
12
+ environmentpath basemodulepath]
11
13
  end
12
14
 
13
15
  def env_keys
@@ -7,7 +7,9 @@ require 'bolt/error'
7
7
  module BoltServer
8
8
  class Config < BoltServer::BaseConfig
9
9
  def config_keys
10
- super + %w[concurrency cache-dir file-server-conn-timeout file-server-uri projects-dir]
10
+ super + %w[concurrency cache-dir file-server-conn-timeout
11
+ file-server-uri projects-dir environments-codedir
12
+ environmentpath basemodulepath]
11
13
  end
12
14
 
13
15
  def env_keys
@@ -64,7 +64,7 @@
64
64
  "description": "Environment the task is in",
65
65
  "type": "string"
66
66
  },
67
- "project": {
67
+ "versioned_project": {
68
68
  "description": "Project the task is in",
69
69
  "type": "string"
70
70
  }
@@ -77,7 +77,7 @@
77
77
  },
78
78
  {
79
79
  "required": [
80
- "project"
80
+ "versioned_project"
81
81
  ]
82
82
  }
83
83
  ],
@@ -235,9 +235,9 @@ module BoltServer
235
235
  #
236
236
  # WARNING: THIS FUNCTION SHOULD ONLY BE CALLED INSIDE A SYNCHRONIZED PAL MUTEX
237
237
  def modulepath_from_environment(environment_name)
238
- codedir = DEFAULT_BOLT_CODEDIR
239
- environmentpath = "#{codedir}/environments"
240
- basemodulepath = "#{codedir}/modules:/opt/puppetlabs/puppet/modules"
238
+ codedir = @config['environments-codedir'] || DEFAULT_BOLT_CODEDIR
239
+ environmentpath = @config['environmentpath'] || "#{codedir}/environments"
240
+ basemodulepath = @config['basemodulepath'] || "#{codedir}/modules:/opt/puppetlabs/puppet/modules"
241
241
  modulepath_dirs = nil
242
242
  with_pe_pal_init_settings(codedir, environmentpath, basemodulepath) do
243
243
  environment = Puppet.lookup(:environments).get!(environment_name)
@@ -543,7 +543,7 @@ module BoltServer
543
543
  return MISSING_PROJECT_REF_RESPONSE if params['project_ref'].nil?
544
544
  in_bolt_project(params['project_ref']) do |context|
545
545
  ps_parameters = {
546
- 'project' => params['project_ref']
546
+ 'versioned_project' => params['project_ref']
547
547
  }
548
548
  task_info = pe_task_info(context[:pal], params[:module_name], params[:task_name], ps_parameters)
549
549
  task_info = allowed_helper(task_info, context[:config].project.tasks)
@@ -645,7 +645,7 @@ module BoltServer
645
645
  # Returns a list of targets parsed from a Project inventory
646
646
  #
647
647
  # @param project_ref [String] the project_ref to compute the inventory from
648
- get '/project_inventory_targets' do
648
+ post '/project_inventory_targets' do
649
649
  return MISSING_PROJECT_REF_RESPONSE if params['project_ref'].nil?
650
650
  bolt_config = config_from_project(params['project_ref'])
651
651
  if bolt_config.inventoryfile && bolt_config.project.inventory_file.to_s != bolt_config.inventoryfile
@@ -74,7 +74,7 @@ begin
74
74
  Puppet::ResourceApi::Transport.inject_device(type, transport)
75
75
 
76
76
  Puppet[:facts_terminus] = :network_device
77
- Puppet[:certname] = conn_info['uri']
77
+ Puppet[:certname] = conn_info['name']
78
78
  end
79
79
 
80
80
  # Ensure custom facts are available for provider suitability tests
@@ -51,7 +51,7 @@ Dir.mktmpdir do |puppet_root|
51
51
  Puppet::ResourceApi::Transport.inject_device(type, transport)
52
52
 
53
53
  Puppet[:facts_terminus] = :network_device
54
- Puppet[:certname] = conn_info['uri']
54
+ Puppet[:certname] = conn_info['name']
55
55
  end
56
56
 
57
57
  facts = Puppet::Node::Facts.indirection.find(SecureRandom.uuid, environment: env)
@@ -59,7 +59,7 @@ Dir.mktmpdir do |puppet_root|
59
59
  Puppet::ResourceApi::Transport.inject_device(type, transport)
60
60
 
61
61
  Puppet[:facts_terminus] = :network_device
62
- Puppet[:certname] = conn_info['uri']
62
+ Puppet[:certname] = conn_info['name']
63
63
  end
64
64
 
65
65
  resources = args['resources'].flat_map do |resource_desc|
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.35.0
4
+ version: 2.36.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-11-16 00:00:00.000000000 Z
11
+ date: 2020-11-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: addressable
@@ -185,9 +185,6 @@ dependencies:
185
185
  - - ">="
186
186
  - !ruby/object:Gem::Version
187
187
  version: 6.18.0
188
- - - "<"
189
- - !ruby/object:Gem::Version
190
- version: '6.20'
191
188
  type: :runtime
192
189
  prerelease: false
193
190
  version_requirements: !ruby/object:Gem::Requirement
@@ -195,9 +192,6 @@ dependencies:
195
192
  - - ">="
196
193
  - !ruby/object:Gem::Version
197
194
  version: 6.18.0
198
- - - "<"
199
- - !ruby/object:Gem::Version
200
- version: '6.20'
201
195
  - !ruby/object:Gem::Dependency
202
196
  name: puppetfile-resolver
203
197
  requirement: !ruby/object:Gem::Requirement
@@ -464,6 +458,7 @@ files:
464
458
  - lib/bolt/config/transport/remote.rb
465
459
  - lib/bolt/config/transport/ssh.rb
466
460
  - lib/bolt/config/transport/winrm.rb
461
+ - lib/bolt/config/validator.rb
467
462
  - lib/bolt/error.rb
468
463
  - lib/bolt/executor.rb
469
464
  - lib/bolt/inventory.rb
@@ -516,11 +511,11 @@ files:
516
511
  - lib/bolt/plugin/puppetdb.rb
517
512
  - lib/bolt/plugin/task.rb
518
513
  - lib/bolt/project.rb
519
- - lib/bolt/project_migrator.rb
520
- - lib/bolt/project_migrator/base.rb
521
- - lib/bolt/project_migrator/config.rb
522
- - lib/bolt/project_migrator/inventory.rb
523
- - lib/bolt/project_migrator/modules.rb
514
+ - lib/bolt/project_manager.rb
515
+ - lib/bolt/project_manager/config_migrator.rb
516
+ - lib/bolt/project_manager/inventory_migrator.rb
517
+ - lib/bolt/project_manager/migrator.rb
518
+ - lib/bolt/project_manager/module_migrator.rb
524
519
  - lib/bolt/puppetdb.rb
525
520
  - lib/bolt/puppetdb/client.rb
526
521
  - lib/bolt/puppetdb/config.rb
@@ -1,80 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'bolt/project_migrator/config'
4
- require 'bolt/project_migrator/inventory'
5
- require 'bolt/project_migrator/modules'
6
-
7
- module Bolt
8
- class ProjectMigrator
9
- def initialize(config, outputter)
10
- @config = config
11
- @outputter = outputter
12
- end
13
-
14
- def migrate
15
- unless $stdin.tty?
16
- raise Bolt::Error.new(
17
- "stdin is not a tty, unable to migrate project",
18
- 'bolt/stdin-not-a-tty-error'
19
- )
20
- end
21
-
22
- @outputter.print_message("Migrating project #{@config.project.path}\n\n")
23
-
24
- @outputter.print_action_step(
25
- "Migrating a Bolt project may make irreversible changes to the project's "\
26
- "configuration and inventory files. Before continuing, make sure the "\
27
- "project has a backup or uses a version control system."
28
- )
29
-
30
- return 0 unless Bolt::Util.prompt_yes_no("Continue with project migration?", @outputter)
31
-
32
- @outputter.print_message('')
33
-
34
- ok = migrate_inventory && migrate_config && migrate_modules
35
-
36
- if ok
37
- @outputter.print_message("Project successfully migrated")
38
- else
39
- @outputter.print_error("Project could not be migrated completely")
40
- end
41
-
42
- ok ? 0 : 1
43
- end
44
-
45
- # Migrates the project-level configuration file to the latest version.
46
- #
47
- private def migrate_config
48
- migrator = Bolt::ProjectMigrator::Config.new(@outputter)
49
-
50
- migrator.migrate(
51
- @config.project.config_file,
52
- @config.project.project_file,
53
- @config.inventoryfile || @config.project.inventory_file,
54
- @config.project.backup_dir
55
- )
56
- end
57
-
58
- # Migrates the inventory file to the latest version.
59
- #
60
- private def migrate_inventory
61
- migrator = Bolt::ProjectMigrator::Inventory.new(@outputter)
62
-
63
- migrator.migrate(
64
- @config.inventoryfile || @config.project.inventory_file,
65
- @config.project.backup_dir
66
- )
67
- end
68
-
69
- # Migrates the project's modules to use current best practices.
70
- #
71
- private def migrate_modules
72
- migrator = Bolt::ProjectMigrator::Modules.new(@outputter)
73
-
74
- migrator.migrate(
75
- @config.project,
76
- @config.modulepath
77
- )
78
- end
79
- end
80
- end