bolt 3.1.0 → 3.3.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 (52) hide show
  1. checksums.yaml +4 -4
  2. data/Puppetfile +8 -8
  3. data/bolt-modules/boltlib/lib/puppet/functions/add_facts.rb +1 -1
  4. data/bolt-modules/boltlib/lib/puppet/functions/run_plan.rb +2 -2
  5. data/bolt-modules/boltlib/lib/puppet/functions/run_script.rb +27 -5
  6. data/bolt-modules/boltlib/lib/puppet/functions/upload_file.rb +1 -1
  7. data/bolt-modules/file/lib/puppet/functions/file/read.rb +3 -2
  8. data/lib/bolt/apply_result.rb +1 -1
  9. data/lib/bolt/bolt_option_parser.rb +6 -3
  10. data/lib/bolt/cli.rb +37 -12
  11. data/lib/bolt/config.rb +4 -0
  12. data/lib/bolt/config/options.rb +21 -3
  13. data/lib/bolt/config/transport/lxd.rb +21 -0
  14. data/lib/bolt/config/transport/options.rb +1 -1
  15. data/lib/bolt/executor.rb +10 -3
  16. data/lib/bolt/logger.rb +8 -0
  17. data/lib/bolt/module_installer.rb +2 -2
  18. data/lib/bolt/module_installer/puppetfile.rb +2 -2
  19. data/lib/bolt/module_installer/specs/forge_spec.rb +2 -2
  20. data/lib/bolt/module_installer/specs/git_spec.rb +2 -2
  21. data/lib/bolt/outputter/human.rb +47 -12
  22. data/lib/bolt/pal.rb +2 -2
  23. data/lib/bolt/pal/yaml_plan.rb +1 -2
  24. data/lib/bolt/pal/yaml_plan/evaluator.rb +5 -141
  25. data/lib/bolt/pal/yaml_plan/step.rb +91 -31
  26. data/lib/bolt/pal/yaml_plan/step/command.rb +16 -16
  27. data/lib/bolt/pal/yaml_plan/step/download.rb +15 -16
  28. data/lib/bolt/pal/yaml_plan/step/eval.rb +11 -11
  29. data/lib/bolt/pal/yaml_plan/step/message.rb +13 -4
  30. data/lib/bolt/pal/yaml_plan/step/plan.rb +19 -15
  31. data/lib/bolt/pal/yaml_plan/step/resources.rb +82 -21
  32. data/lib/bolt/pal/yaml_plan/step/script.rb +32 -17
  33. data/lib/bolt/pal/yaml_plan/step/task.rb +19 -16
  34. data/lib/bolt/pal/yaml_plan/step/upload.rb +16 -17
  35. data/lib/bolt/pal/yaml_plan/transpiler.rb +1 -1
  36. data/lib/bolt/plan_creator.rb +1 -1
  37. data/lib/bolt/project_manager.rb +1 -1
  38. data/lib/bolt/project_manager/module_migrator.rb +1 -1
  39. data/lib/bolt/shell.rb +16 -0
  40. data/lib/bolt/shell/bash.rb +48 -21
  41. data/lib/bolt/shell/bash/tmpdir.rb +2 -2
  42. data/lib/bolt/shell/powershell.rb +24 -5
  43. data/lib/bolt/task.rb +1 -1
  44. data/lib/bolt/transport/lxd.rb +26 -0
  45. data/lib/bolt/transport/lxd/connection.rb +99 -0
  46. data/lib/bolt/transport/ssh/connection.rb +1 -1
  47. data/lib/bolt/transport/winrm/connection.rb +1 -1
  48. data/lib/bolt/version.rb +1 -1
  49. data/lib/bolt_server/transport_app.rb +13 -1
  50. data/lib/bolt_spec/plans/action_stubs.rb +1 -1
  51. data/lib/bolt_spec/plans/mock_executor.rb +4 -0
  52. metadata +5 -2
@@ -0,0 +1,99 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'logging'
4
+ require 'bolt/node/errors'
5
+
6
+ module Bolt
7
+ module Transport
8
+ class LXD < Simple
9
+ class Connection
10
+ attr_reader :user, :target
11
+
12
+ def initialize(target, options)
13
+ raise Bolt::ValidationError, "Target #{target.safe_name} does not have a host" unless target.host
14
+
15
+ @target = target
16
+ @user = ENV['USER'] || Etc.getlogin
17
+ @options = options
18
+ @logger = Bolt::Logger.logger(target.safe_name)
19
+ @logger.trace("Initializing LXD connection to #{target.safe_name}")
20
+ end
21
+
22
+ def shell
23
+ Bolt::Shell::Bash.new(target, self)
24
+ end
25
+
26
+ def container_id
27
+ "local:#{@target.host}"
28
+ end
29
+
30
+ def connect
31
+ out, err, status = execute_local_command(%w[list --format json])
32
+ unless status.exitstatus.zero?
33
+ raise "Error listing available containers: #{err}"
34
+ end
35
+ containers = JSON.parse(out).map { |c| c['name'] }
36
+ unless containers.include?(@target.host)
37
+ raise "Could not find a container with name or ID matching '#{@target.host}'"
38
+ end
39
+ @logger.trace("Opened session")
40
+ true
41
+ rescue StandardError => e
42
+ raise Bolt::Node::ConnectError.new(
43
+ "Failed to connect to #{container_id}: #{e.message}",
44
+ 'CONNECT_ERROR'
45
+ )
46
+ end
47
+
48
+ def add_env_vars(env_vars)
49
+ @env_vars = env_vars.each_with_object([]) do |env_var, acc|
50
+ acc << "--env"
51
+ acc << "#{env_var[0]}=#{Shellwords.shellescape(env_var[1])}"
52
+ end
53
+ end
54
+
55
+ def execute(command)
56
+ lxc_command = %w[lxc exec]
57
+ lxc_command += @env_vars if @env_vars
58
+ lxc_command += %W[#{container_id} -- sh -c #{Shellwords.shellescape(command)}]
59
+
60
+ @logger.trace { "Executing: #{lxc_command.join(' ')}" }
61
+ Open3.popen3(lxc_command.join(' '))
62
+ end
63
+
64
+ private def execute_local_command(command)
65
+ Open3.capture3('lxc', *command, { binmode: true })
66
+ end
67
+
68
+ def upload_file(source, destination)
69
+ @logger.trace { "Uploading #{source} to #{destination}" }
70
+ args = %w[--create-dirs]
71
+ if File.directory?(source)
72
+ args << '--recursive'
73
+ # If we don't do this, LXD will upload to
74
+ # /tmp/d2020-11/d2020-11/dir instead of /tmp/d2020-11/dir
75
+ destination = Pathname.new(destination).dirname.to_s
76
+ end
77
+ cmd = %w[file push] + args + %W[#{source} #{container_id}#{destination}]
78
+ _out, err, stat = execute_local_command(cmd)
79
+ unless stat.exitstatus.zero?
80
+ raise "Error writing to #{container_id}: #{err}"
81
+ end
82
+ rescue StandardError => e
83
+ raise Bolt::Node::FileError.new(e.message, 'WRITE_ERROR')
84
+ end
85
+
86
+ def download_file(source, destination, _download)
87
+ @logger.trace { "Downloading #{source} to #{destination}" }
88
+ FileUtils.mkdir_p(destination)
89
+ _out, err, stat = execute_local_command(%W[file pull --recursive #{container_id}#{source} #{destination}])
90
+ unless stat.exitstatus.zero?
91
+ raise "Error downloading content from container #{container_id}: #{err}"
92
+ end
93
+ rescue StandardError => e
94
+ raise Bolt::Node::FileError.new(e.message, 'WRITE_ERROR')
95
+ end
96
+ end
97
+ end
98
+ end
99
+ end
@@ -230,7 +230,7 @@ module Bolt
230
230
  end
231
231
  [in_wr, out_rd, err_rd, th]
232
232
  rescue Errno::EMFILE => e
233
- msg = "#{e.message}. This may be resolved by increasing your user limit "\
233
+ msg = "#{e.message}. This might be resolved by increasing your user limit "\
234
234
  "with 'ulimit -n 1024'. See https://puppet.com/docs/bolt/latest/bolt_known_issues.html for details."
235
235
  raise Bolt::Error.new(msg, 'bolt/too-many-files')
236
236
  end
@@ -130,7 +130,7 @@ module Bolt
130
130
 
131
131
  [inp, out_rd, err_rd, th]
132
132
  rescue Errno::EMFILE => e
133
- msg = "#{e.message}. This may be resolved by increasing your user limit "\
133
+ msg = "#{e.message}. This might be resolved by increasing your user limit "\
134
134
  "with 'ulimit -n 1024'. See https://puppet.com/docs/bolt/latest/bolt_known_issues.html for details."
135
135
  raise Bolt::Error.new(msg, 'bolt/too-many-files')
136
136
  rescue StandardError
data/lib/bolt/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Bolt
4
- VERSION = '3.1.0'
4
+ VERSION = '3.3.0'
5
5
  end
@@ -690,11 +690,23 @@ module BoltServer
690
690
  Bolt::Util.validate_file('inventory file', context[:config].project.inventory_file)
691
691
 
692
692
  begin
693
+ # Set the default puppet_library plugin hook if it has not already been
694
+ # set
695
+ context[:config].data['plugin-hooks']['puppet_library'] ||= {
696
+ 'plugin' => 'task',
697
+ 'task' => 'puppet_agent::install',
698
+ 'parameters' => {
699
+ 'stop_service' => true
700
+ }
701
+ }
702
+
693
703
  connect_plugin = BoltServer::Plugin::PuppetConnectData.new(body['puppet_connect_data'])
694
704
  plugins = Bolt::Plugin.setup(context[:config], context[:pal], load_plugins: false)
695
705
  plugins.add_plugin(connect_plugin)
696
706
  inventory = Bolt::Inventory.from_config(context[:config], plugins)
697
- target_list = inventory.get_targets('all').map { |targ| targ.to_h.merge({ 'transport' => targ.transport }) }
707
+ target_list = inventory.get_targets('all').map do |targ|
708
+ targ.to_h.merge({ 'transport' => targ.transport, 'plugin_hooks' => targ.plugin_hooks })
709
+ end
698
710
  rescue Bolt::Plugin::PluginError::LoadingDisabled => e
699
711
  msg = "Cannot load plugin #{e.details['plugin_name']}: plugin not supported"
700
712
  raise BoltServer::Plugin::PluginNotSupported.new(msg, e.details['plugin_name'])
@@ -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()' might require msg and kind, and " \
181
181
  "optionally accept only details and issue_code."
182
182
  @data[:default] = data
183
183
  end
@@ -214,8 +214,12 @@ module BoltSpec
214
214
 
215
215
  def report_bundled_content(_mode, _name); end
216
216
 
217
+ def report_file_source(_plan_function, _source); end
218
+
217
219
  def report_apply(_statements, _resources); end
218
220
 
221
+ def report_yaml_plan(_plan); end
222
+
219
223
  def publish_event(event)
220
224
  if event[:type] == :message
221
225
  unless @stub_out_message
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: 3.1.0
4
+ version: 3.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Puppet
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-03-01 00:00:00.000000000 Z
11
+ date: 2021-03-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: addressable
@@ -467,6 +467,7 @@ files:
467
467
  - lib/bolt/config/transport/base.rb
468
468
  - lib/bolt/config/transport/docker.rb
469
469
  - lib/bolt/config/transport/local.rb
470
+ - lib/bolt/config/transport/lxd.rb
470
471
  - lib/bolt/config/transport/options.rb
471
472
  - lib/bolt/config/transport/orch.rb
472
473
  - lib/bolt/config/transport/remote.rb
@@ -555,6 +556,8 @@ files:
555
556
  - lib/bolt/transport/docker/connection.rb
556
557
  - lib/bolt/transport/local.rb
557
558
  - lib/bolt/transport/local/connection.rb
559
+ - lib/bolt/transport/lxd.rb
560
+ - lib/bolt/transport/lxd/connection.rb
558
561
  - lib/bolt/transport/orch.rb
559
562
  - lib/bolt/transport/orch/connection.rb
560
563
  - lib/bolt/transport/remote.rb