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.
- checksums.yaml +4 -4
- data/Puppetfile +8 -8
- data/bolt-modules/boltlib/lib/puppet/functions/add_facts.rb +1 -1
- data/bolt-modules/boltlib/lib/puppet/functions/run_plan.rb +2 -2
- data/bolt-modules/boltlib/lib/puppet/functions/run_script.rb +27 -5
- data/bolt-modules/boltlib/lib/puppet/functions/upload_file.rb +1 -1
- data/bolt-modules/file/lib/puppet/functions/file/read.rb +3 -2
- data/lib/bolt/apply_result.rb +1 -1
- data/lib/bolt/bolt_option_parser.rb +6 -3
- data/lib/bolt/cli.rb +37 -12
- data/lib/bolt/config.rb +4 -0
- data/lib/bolt/config/options.rb +21 -3
- data/lib/bolt/config/transport/lxd.rb +21 -0
- data/lib/bolt/config/transport/options.rb +1 -1
- data/lib/bolt/executor.rb +10 -3
- data/lib/bolt/logger.rb +8 -0
- data/lib/bolt/module_installer.rb +2 -2
- data/lib/bolt/module_installer/puppetfile.rb +2 -2
- data/lib/bolt/module_installer/specs/forge_spec.rb +2 -2
- data/lib/bolt/module_installer/specs/git_spec.rb +2 -2
- data/lib/bolt/outputter/human.rb +47 -12
- data/lib/bolt/pal.rb +2 -2
- data/lib/bolt/pal/yaml_plan.rb +1 -2
- data/lib/bolt/pal/yaml_plan/evaluator.rb +5 -141
- data/lib/bolt/pal/yaml_plan/step.rb +91 -31
- data/lib/bolt/pal/yaml_plan/step/command.rb +16 -16
- data/lib/bolt/pal/yaml_plan/step/download.rb +15 -16
- data/lib/bolt/pal/yaml_plan/step/eval.rb +11 -11
- data/lib/bolt/pal/yaml_plan/step/message.rb +13 -4
- data/lib/bolt/pal/yaml_plan/step/plan.rb +19 -15
- data/lib/bolt/pal/yaml_plan/step/resources.rb +82 -21
- data/lib/bolt/pal/yaml_plan/step/script.rb +32 -17
- data/lib/bolt/pal/yaml_plan/step/task.rb +19 -16
- data/lib/bolt/pal/yaml_plan/step/upload.rb +16 -17
- data/lib/bolt/pal/yaml_plan/transpiler.rb +1 -1
- data/lib/bolt/plan_creator.rb +1 -1
- data/lib/bolt/project_manager.rb +1 -1
- data/lib/bolt/project_manager/module_migrator.rb +1 -1
- data/lib/bolt/shell.rb +16 -0
- data/lib/bolt/shell/bash.rb +48 -21
- data/lib/bolt/shell/bash/tmpdir.rb +2 -2
- data/lib/bolt/shell/powershell.rb +24 -5
- data/lib/bolt/task.rb +1 -1
- data/lib/bolt/transport/lxd.rb +26 -0
- data/lib/bolt/transport/lxd/connection.rb +99 -0
- data/lib/bolt/transport/ssh/connection.rb +1 -1
- data/lib/bolt/transport/winrm/connection.rb +1 -1
- data/lib/bolt/version.rb +1 -1
- data/lib/bolt_server/transport_app.rb +13 -1
- data/lib/bolt_spec/plans/action_stubs.rb +1 -1
- data/lib/bolt_spec/plans/mock_executor.rb +4 -0
- 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
|
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
|
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
@@ -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
|
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()'
|
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.
|
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-
|
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
|