Skip to content

(#13091) Fix LoadError exception with puppet apply #50

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions lib/facter/facter_dot_d.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
# 600 file and will have the end result of not calling your
# fact scripts more often than is needed

require 'facter/util/puppet_settings'

class Facter::Util::DotD
require 'yaml'

Expand Down
12 changes: 11 additions & 1 deletion lib/facter/puppet_vardir.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,17 @@
# regardless of the node's platform.
#
# The value should be directly usable in a File resource path attribute.
require 'facter/util/puppet_settings'


begin
require 'facter/util/puppet_settings'
rescue LoadError => e
# puppet apply does not add module lib directories to the $LOAD_PATH (See
# #4248). It should (in the future) but for the time being we need to be
# defensive which is what this rescue block is doing.
rb_file = File.join(File.dirname(__FILE__), 'util', 'puppet_settings.rb')
load rb_file if File.exists?(rb_file) or raise e
end

Facter.add(:puppet_vardir) do
setcode do
Expand Down
22 changes: 13 additions & 9 deletions lib/facter/util/puppet_settings.rb
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
module Facter
module Util
module PuppetSettings
class << self
def with_puppet
begin
Module.const_get("Puppet")
rescue NameError
nil
else
yield
end
# This method is intended to provide a convenient way to evaluate a
# Facter code block only if Puppet is loaded. This is to account for the
# situation where the fact happens to be in the load path, but Puppet is
# not loaded for whatever reason. Perhaps the user is simply running
# facter without the --puppet flag and they happen to be working in a lib
# directory of a module.
def self.with_puppet
begin
Module.const_get("Puppet")
rescue NameError
nil
else
yield
end
end
end
Expand Down