From df788d858f5a3ee4796da93d3ef8c0461abadaa2 Mon Sep 17 00:00:00 2001 From: Valters Jansons Date: Thu, 4 Feb 2021 21:21:54 +0200 Subject: [PATCH] Require `puppet_x/helper.rb` based on full path Not all code ends up in Puppet Ruby LOAD_PATH. We are running a fleet of Puppet 6.20.0 and Puppet 7.3.0 nodes, which cannot autoload `puppet/provider/package/windowspowershell` as there is no such file to load -- `puppet_x/encore/powershellmodule/helper`. Using a dynamically expanded path from the `lib/puppet/` files seems to very much so do the trick. There was a 2012 O'Reilly book talking about this as well. Might not be the newest and greatest solution, as it would be possible to work with LOAD_PATH, but this solves the underlying catalog generation error. Book: Puppet Types and Providers: Chapter 4: Shared Libraries > https://www.oreilly.com/library/view/puppet-types-and/9781449339319/ch04.html --- CHANGELOG.md | 6 ++++++ lib/puppet/provider/package/powershellcore.rb | 2 +- lib/puppet/provider/package/windowspowershell.rb | 2 +- lib/puppet/provider/pspackageprovider/powershellcore.rb | 2 +- lib/puppet/provider/pspackageprovider/windowspowershell.rb | 2 +- lib/puppet/provider/psrepository/powershellcore.rb | 2 +- lib/puppet/provider/psrepository/windowspowershell.rb | 2 +- 7 files changed, 12 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fb14a21..1b185a8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ ## Development +* Replaced the require call for `puppet_x` helper library to use a dynamically + expanded path. This works around limitations in Puppet Ruby `LOAD_PATH` + with error `no such file to load -- puppet_x/encore/powershellmodule/helper`. + + Contributed by Valters Jansons (@sigv) + ## 2.2.0 (2020-11-12) * Added PowerShell runtime caching using `ruby-pwsh` gem and the `puppetlabs/pwshlib` forge module diff --git a/lib/puppet/provider/package/powershellcore.rb b/lib/puppet/provider/package/powershellcore.rb index 5bd0c65..8539241 100644 --- a/lib/puppet/provider/package/powershellcore.rb +++ b/lib/puppet/provider/package/powershellcore.rb @@ -1,6 +1,6 @@ require 'puppet/provider/package' require 'json' -require 'puppet_x/encore/powershellmodule/helper' +require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', '..', 'puppet_x', 'encore', 'powershellmodule', 'helper.rb')) Puppet::Type.type(:package).provide :powershellcore, parent: Puppet::Provider::Package do initvars diff --git a/lib/puppet/provider/package/windowspowershell.rb b/lib/puppet/provider/package/windowspowershell.rb index 19e9592..4e6003f 100644 --- a/lib/puppet/provider/package/windowspowershell.rb +++ b/lib/puppet/provider/package/windowspowershell.rb @@ -1,4 +1,4 @@ -require 'puppet_x/encore/powershellmodule/helper' +require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', '..', 'puppet_x', 'encore', 'powershellmodule', 'helper.rb')) Puppet::Type.type(:package).provide(:windowspowershell, parent: :powershellcore) do initvars diff --git a/lib/puppet/provider/pspackageprovider/powershellcore.rb b/lib/puppet/provider/pspackageprovider/powershellcore.rb index 6bd616f..8aa0482 100644 --- a/lib/puppet/provider/pspackageprovider/powershellcore.rb +++ b/lib/puppet/provider/pspackageprovider/powershellcore.rb @@ -1,5 +1,5 @@ require 'json' -require 'puppet_x/encore/powershellmodule/helper' +require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', '..', 'puppet_x', 'encore', 'powershellmodule', 'helper.rb')) Puppet::Type.type(:pspackageprovider).provide :powershellcore do confine operatingsystem: :windows diff --git a/lib/puppet/provider/pspackageprovider/windowspowershell.rb b/lib/puppet/provider/pspackageprovider/windowspowershell.rb index f90827f..296ee6e 100644 --- a/lib/puppet/provider/pspackageprovider/windowspowershell.rb +++ b/lib/puppet/provider/pspackageprovider/windowspowershell.rb @@ -1,4 +1,4 @@ -require 'puppet_x/encore/powershellmodule/helper' +require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', '..', 'puppet_x', 'encore', 'powershellmodule', 'helper.rb')) Puppet::Type.type(:pspackageprovider).provide(:windowspowershell, parent: :powershellcore) do confine operatingsystem: :windows diff --git a/lib/puppet/provider/psrepository/powershellcore.rb b/lib/puppet/provider/psrepository/powershellcore.rb index 8bff1fe..4a30d6a 100644 --- a/lib/puppet/provider/psrepository/powershellcore.rb +++ b/lib/puppet/provider/psrepository/powershellcore.rb @@ -1,4 +1,4 @@ -require 'puppet_x/encore/powershellmodule/helper' +require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', '..', 'puppet_x', 'encore', 'powershellmodule', 'helper.rb')) Puppet::Type.type(:psrepository).provide(:powershellcore) do initvars diff --git a/lib/puppet/provider/psrepository/windowspowershell.rb b/lib/puppet/provider/psrepository/windowspowershell.rb index 5bc7b01..3f46025 100644 --- a/lib/puppet/provider/psrepository/windowspowershell.rb +++ b/lib/puppet/provider/psrepository/windowspowershell.rb @@ -1,4 +1,4 @@ -require 'puppet_x/encore/powershellmodule/helper' +require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', '..', 'puppet_x', 'encore', 'powershellmodule', 'helper.rb')) Puppet::Type.type(:psrepository).provide(:windowspowershell, parent: :powershellcore) do initvars