From c0b338ccb6f014a87d0aca4c17745e7852eaf4dd Mon Sep 17 00:00:00 2001 From: donoghuc Date: Fri, 17 May 2024 12:23:40 -0700 Subject: [PATCH] (GH-3310) Load bolt builtin content if it is present This commit shows an alternate approach for handling bundled-ruby: true on local transport for core types and providers. Instead of always syncing those plugins (almost always not-necessary) we simply pass through the buitin content location to the apply_catalog task. If it is detected on the target, builtin content is added to the loadpath. This allows us to avoid pluginsyncing when its not always necessary and handing the case of local transport. --- lib/bolt/applicator.rb | 1 + libexec/apply_catalog.rb | 13 +++++++++++++ 2 files changed, 14 insertions(+) diff --git a/lib/bolt/applicator.rb b/lib/bolt/applicator.rb index eaf4d0da0e..69023210ba 100644 --- a/lib/bolt/applicator.rb +++ b/lib/bolt/applicator.rb @@ -284,6 +284,7 @@ def apply_ast(raw_ast, targets, options, plan_vars = {}) 'catalog' => Puppet::Pops::Types::PSensitiveType::Sensitive.new(catalog), 'plugins' => Puppet::Pops::Types::PSensitiveType::Sensitive.new(plugins), 'apply_settings' => @apply_settings, + 'bolt_builtin_content' => @modulepath.full_modulepath - @modulepath.user_modulepath || [], '_task' => catalog_apply_task.name, '_noop' => options[:noop] } diff --git a/libexec/apply_catalog.rb b/libexec/apply_catalog.rb index ccf6d62232..de12b8cc44 100755 --- a/libexec/apply_catalog.rb +++ b/libexec/apply_catalog.rb @@ -52,6 +52,19 @@ $LOAD_PATH << dir unless $LOAD_PATH.include?(dir) end + # In the case we are applying on a bolt runner and using bundled-ruby over local transport + # we will want to load code shipped with bolt. This is last on the load path and therefore + # explicitly packaged plugins should take precedence + args['bolt_builtin_content'].each do |builtin_dir| + next unless Dir.exist?(builtin_dir) + Dir.foreach(builtin_dir) do |dir| + unless ['.', '..'].include? dir + full_path = File.join(builtin_dir, dir, 'lib') + $LOAD_PATH << full_path unless $LOAD_PATH.include?(full_path) + end + end + end + if (conn_info = args['_target']) unless (type = conn_info['remote-transport']) puts "Cannot execute a catalog for a remote target without knowing it's the remote-transport type."