Details
-
Bug
-
Status: Resolved
-
Normal
-
Resolution: Fixed
-
None
-
None
-
Night's Watch
-
5
-
NW - 2021-03-03
-
Needs Assessment
-
Bug Fix
-
Fixed a bug where `Facter.value` was not always returning the fact value for a legacy fact. This was observed when calling a legacy fact from a custom fact or calling other Facter API methods before calling value.
-
Needs Assessment
Description
When running `puppet facts show` and puppetlabs-stdlib is installed, the following error message is shown:
Error: Could not autoload puppet/provider/service/init: undefined method `downcase' for nil:NilClass
|
Error: Could not autoload puppet/provider/service/bsd: Could not autoload puppet/provider/service/init: undefined method `downcase' for nil:NilClass
|
Error: Facter: error while resolving custom facts in /etc/puppetlabs/code/modules/stdlib/lib/facter/service_provider.rb Could not autoload puppet/provider/service/bsd: Could not autoload puppet/provider/service/init: undefined method `downcase' for nil:NilClass
|
- puppet facts show calls `Facter.resolve` which sets show_legacy to false
- when resolving facts, Facter also load modules facts(stdlib)
- stdlib has a fact that creates a dummy provider: https://github.com/puppetlabs/puppetlabs-stdlib/blob/main/lib/facter/service_provider.rb
- when Facter loads that fact, it calls Puppet to initalize the provider, Puppet tries to see what specific provider is suitable, and when it gets to `init.rb` it calls Facter back, with `operatingsystem`
- because `Facter::Options[:show_legacy]` is false, Facter.value(:operatingsystem) returns `nil`, which breaks the call of `downcase`: https://github.com/puppetlabs/puppet/blob/main/lib/puppet/provider/service/init.rb#L24
This happens because `Facter::Options` is globally set for the entire run.
Note that the command is working, and running "puppet facts show fact" does not log any error