Skip to content

Commit

Permalink
Require puppet_x/helper.rb based on full path
Browse files Browse the repository at this point in the history
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
  • Loading branch information
sigv committed Feb 4, 2021
1 parent aadef25 commit df788d8
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 6 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/puppet/provider/package/powershellcore.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/puppet/provider/package/windowspowershell.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/puppet/provider/pspackageprovider/powershellcore.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/puppet/provider/pspackageprovider/windowspowershell.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/puppet/provider/psrepository/powershellcore.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/puppet/provider/psrepository/windowspowershell.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit df788d8

Please sign in to comment.