theforeman / puppet-foreman

Puppet module for Foreman
GNU General Public License v3.0
104 stars 270 forks source link

Error shown on Windows hosts #283

Closed genebean closed 9 years ago

genebean commented 9 years ago

This error is shown on all my Windows nodes. I assume that something is trying to be done by way of stuff that comes over (or doesn't) via module sync.

PS C:\Windows\system32> puppet agent -t
Info: Retrieving pluginfacts
Info: Retrieving plugin
Info: Loading facts
Error loading fact C:/ProgramData/PuppetLabs/puppet/var/lib/facter/facts.rb: cannot load such file -- util/sssd
ekohl commented 9 years ago

I'm unfamiliar with puppet on windows so we're going to have to see how far we can come here. Can you share which files do exist on .../var/lib/facter?

lazyfrosch commented 9 years ago

That is the fact "facts" inside this module: foreman/lib/facter/facts.rb

I guess sssd Ruby stuff is not available on a Windows.

Though the fact should not fail, but silently doing nothing. We need to catch that second require there...

lazyfrosch commented 9 years ago

Also it might be not a good idea to name this file "facts.rb", that is a single namespace...

genebean commented 9 years ago

So... here is what I have on a Windows host:

PS D:\> cd c:\ProgramData\PuppetLabs\puppet\var\lib\facter
PS C:\ProgramData\PuppetLabs\puppet\var\lib\facter> dir

    Directory: C:\ProgramData\PuppetLabs\puppet\var\lib\facter

Mode                LastWriteTime     Length Name
----                -------------     ------ ----
d----          2/2/2015   8:49 PM            util
-a---          2/2/2015   8:49 PM        920 apt_updates.rb
-a---          2/2/2015   8:49 PM        597 apt_update_last_success.rb
-a---          2/2/2015   8:49 PM        212 concat_basedir.rb
-a---          2/2/2015   8:49 PM       1127 eselect.rb
-a---          2/2/2015   8:49 PM       4667 facter_dot_d.rb
-a---          2/2/2015   8:49 PM       1072 facts.rb
-a---          2/2/2015   8:49 PM        218 gemhome.rb
-a---          2/2/2015   8:49 PM        236 ip6tables_version.rb
-a---          2/2/2015   8:49 PM        444 iptables_persistent_version.rb
-a---          2/2/2015   8:49 PM        234 iptables_version.rb
-a---          2/2/2015   8:49 PM       2520 oracle_database_homes.rb
-a---          2/2/2015   8:49 PM       1172 pe_version.rb
-a---          2/2/2015   8:49 PM        210 portage.rb
-a---          2/2/2015   8:49 PM        937 puppet_vardir.rb
-a---          2/2/2015   8:49 PM        104 r10k_environment.rb
-a---          2/2/2015   8:49 PM        875 root_home.rb
-a---          2/2/2015   8:49 PM        618 staging_http_get.rb
-a---          2/2/2015   8:49 PM        251 staging_windir.rb
-a---          2/2/2015   8:49 PM        232 sudoversion.rb

And here is the util directory:

Mode                LastWriteTime     Length Name
----                -------------     ------ ----
-a---          2/2/2015   8:49 PM        432 portage.rb
-a---          2/2/2015   8:49 PM        660 puppet_settings.rb
-a---          2/2/2015   8:49 PM        481 sssd.rb

If I look in facts.rb (which, I agree, could do with renaming) I see all the sssd stuff. Originally, I mistakenly thought this was a Puppet bug so I opened FACT-798 and in there it was suggested that a confine based on kernel was needed in the fact.

ekohl commented 9 years ago

My guess is that there's no augeas on windows and that it fails because of it.

logicminds commented 9 years ago

Is plugin sync enabled? the facts.rb is a foreman custom fact. It it looks like its not loading into your lib ruby path correctly.

genebean commented 9 years ago

Yep, its on.

lazyfrosch commented 9 years ago

Yeah that might actually be the problem that augeas inside sssd.rb can not be loaded:

# facts.rb
begin
  require 'facter/util/sssd' # NOTE: augeas failed to load inside
rescue LoadError
  # Puppet 2 compatibility, facter/ dir is the load path, not lib/
  require 'util/sssd' # NOTE: fails because it's NOT Puppet 2
end

Any good idea how to skip that fact if augeas is not available?

domcleal commented 9 years ago

In util/sssd.rb we could do:

begin
  require 'augeas'
  module Facter::Util::Sssd
     # ...
  end
rescue LoadError => e
  Facter.debug("Cannot load Augeas library for custom facts: #{e}")
end

And in facts.rb (that really needs renaming to not be generic):

if defined? Facter::Util::Sssd
  Facter.add .....
  Facter.add .....
end            
ekohl commented 9 years ago

I think the solution @domcleal wrote sounds good. Anyone willing and able to come up with patches?