lib/bolt/applicator.rb in bolt-0.24.0 vs lib/bolt/applicator.rb in bolt-0.25.0
- old
+ new
@@ -6,10 +6,11 @@
require 'json'
require 'logging'
require 'minitar'
require 'open3'
require 'bolt/task'
+require 'bolt/apply_result'
require 'bolt/util/puppet_log_level'
module Bolt
class Applicator
def initialize(inventory, executor, modulepath, plugin_dirs, pdb_client, hiera_config, max_compiles)
@@ -111,60 +112,10 @@
end
hiera_config
end
end
- def provide_puppet_missing_errors(result)
- error_hash = result.error_hash
- exit_code = error_hash['details']['exit_code'] if error_hash && error_hash['details']
- # If we get exit code 126 or 127 back, it means the shebang command wasn't found; Puppet isn't present
- if [126, 127].include?(exit_code)
- Result.new(result.target, error:
- {
- 'msg' => "Puppet is not installed on the target, please install it to enable 'apply'",
- 'kind' => 'bolt/apply-error'
- })
- elsif exit_code == 1 &&
- (error_hash['msg'] =~ /Could not find executable 'ruby.exe'/ ||
- error_hash['msg'] =~ /The term 'ruby.exe' is not recognized as the name of a cmdlet/)
- # Windows does not have Ruby present
- Result.new(result.target, error:
- {
- 'msg' => "Puppet is not installed on the target in $env:ProgramFiles, please install it to enable 'apply'",
- 'kind' => 'bolt/apply-error'
- })
- elsif exit_code == 1 && error_hash['msg'] =~ /cannot load such file -- puppet \(LoadError\)/
- # Windows uses a Ruby that doesn't have Puppet installed
- # TODO: fix so we don't find other Rubies, or point to a known issues URL for more info
- Result.new(result.target, error:
- {
- 'msg' => 'Found a Ruby without Puppet present, please install Puppet ' \
- "or remove Ruby from $env:Path to enable 'apply'",
- 'kind' => 'bolt/apply-error'
- })
- else
- result
- end
- end
-
- def identify_resource_failures(result)
- if result.ok? && result.value['status'] == 'failed'
- resources = result.value['resource_statuses']
- failed = resources.select { |_, r| r['failed'] }.flat_map do |key, resource|
- resource['events'].select { |e| e['status'] == 'failure' }.map do |event|
- "\n #{key}: #{event['message']}"
- end
- end
-
- result.value['_error'] = {
- 'msg' => "Resources failed to apply for #{result.target.name}#{failed.join}",
- 'kind' => 'bolt/resource-failure'
- }
- end
- result
- end
-
def apply(args, apply_body, scope)
raise(ArgumentError, 'apply requires a TargetSpec') if args.empty?
type0 = Puppet.lookup(:pal_script_compiler).type('TargetSpec')
Puppet::Pal.assert_type(type0, args[0], 'apply targets')
@@ -195,15 +146,17 @@
end
result_promises = targets.zip(futures).flat_map do |target, future|
@executor.queue_execute([target]) do |transport, batch|
@executor.with_node_logging("Applying manifest block", batch) do
- arguments = { 'catalog' => future.value, 'plugins' => plugins, '_noop' => options['_noop'] }
+ arguments = {
+ 'catalog' => Puppet::Pops::Types::PSensitiveType::Sensitive.new(future.value),
+ 'plugins' => Puppet::Pops::Types::PSensitiveType::Sensitive.new(plugins),
+ '_noop' => options['_noop']
+ }
raise future.reason if future.rejected?
results = transport.batch_task(batch, catalog_apply_task, arguments, options, ¬ify)
- Array(results).map do |result|
- identify_resource_failures(provide_puppet_missing_errors(result))
- end
+ Array(results).map { |result| ApplyResult.from_task_result(result) }
end
end
end
@executor.await_results(result_promises)