Jira (FACT-2880) facter 4 differing output from facter 3 for service_provider fact

36 views
Skip to first unread message

Matt Darcy (Jira)

unread,
Nov 30, 2020, 9:00:03 AM11/30/20
to puppe...@googlegroups.com
Matt Darcy created an issue
 
Facter / Bug FACT-2880
facter 4 differing output from facter 3 for service_provider fact
Issue Type: Bug Bug
Affects Versions: FACT 4.0.44
Assignee: Unassigned
Components: Facter 4
Created: 2020/11/30 5:59 AM
Environment:

raspberry pi model 4b running Raspbian (but also appears in Debian arm build) 

Puppet 5.5.10 / Facter 3.11.0 service_provider = systemd

Puppet 6.19.0 / Facter 4.0.46 service_provider = 'base'

Puppet 7.0.0. / Facter 4.0.46 service_provider = 'base' 

unable to verify other combinations on this hardware due to lack of facter 3 available for arm.

 

Puppet 6.19.0 / Facter 3.14.9 on x86_64 service_provider = systemd 

 

 

Priority: Normal Normal
Reporter: Matt Darcy

running a puppet module that uses the fact 'service_provider' from stdlib on a Raspbian 10.6 host with puppet 5 and facter 3 the output of 'service_provider' is 'systemd' as expeted.

on an identical hardware device using puppet 6.19 and facter 4.0.46 provided by ruby gems the output changes from systemd to 'base' 

Changing the puppet version to puppet 7 and facter 4.0.46 the behaviour is consistent and provides the output 'base' 

Add Comment Add Comment
 
This message was sent by Atlassian Jira (v8.5.2#805002-sha1:a66f935)
Atlassian logo

Tim Meusel (Jira)

unread,
Nov 30, 2020, 9:10:09 AM11/30/20
to puppe...@googlegroups.com
Tim Meusel commented on Bug FACT-2880
 
Re: facter 4 differing output from facter 3 for service_provider fact

Hey,
I've some more output as well (both from CentOS 7 nodes that use the official Puppet packages):

 ~ # puppet --version
7.0.0
 ~ # facter --version
4.0.46
 ~ # puppet resource service sshd
service { 'sshd':
  ensure   => 'running',
  provider => 'base',
}
 ~ #

this works with the normal puppet 6:

 ~ # puppet --version
6.19.1
 ~ # facter --version
3.14.14 (commit e36657bea27254f003c8fc71d8ef57454db643e2)
 ~ # puppet resource service sshd
service { 'sshd':
  ensure   => 'running',
  enable   => 'true',
  provider => 'systemd',
}
 ~ # 

Matt Darcy (Jira)

unread,
Dec 1, 2020, 4:11:05 AM12/1/20
to puppe...@googlegroups.com
Matt Darcy commented on Bug FACT-2880

results are consistent with various versions of stdlib in place, can provide detailed breakdown if requested.

Josh Cooper (Jira)

unread,
Dec 1, 2020, 10:21:03 AM12/1/20
to puppe...@googlegroups.com

Oana Tanasoiu (Jira)

unread,
Dec 2, 2020, 1:40:04 AM12/2/20
to puppe...@googlegroups.com

Oana Tanasoiu (Jira)

unread,
Dec 2, 2020, 1:40:04 AM12/2/20
to puppe...@googlegroups.com
Oana Tanasoiu updated an issue
Change By: Oana Tanasoiu
Sub-team: ghost
Team: Night's Watch

Bogdan Irimie (Jira)

unread,
Dec 2, 2020, 2:57:03 AM12/2/20
to puppe...@googlegroups.com
Bogdan Irimie updated an issue
Change By: Bogdan Irimie
Sprint: ready for triage ghost-2.12

Mihai Buzgau (Jira)

unread,
Dec 2, 2020, 5:40:04 AM12/2/20
to puppe...@googlegroups.com
Mihai Buzgau commented on Bug FACT-2880
 
Re: facter 4 differing output from facter 3 for service_provider fact

Tim Meusel Matt Darcy can you please provide the output for the following commands:

puppet resource service sshd --debug 

and for

facter os --debug 

since we were not able to reproduce this on the above-mentioned OSes it would be great if you could paste the output for both Puppet 6 and Puppet 7

Tim Meusel (Jira)

unread,
Dec 2, 2020, 6:08:04 AM12/2/20
to puppe...@googlegroups.com
Tim Meusel commented on Bug FACT-2880

Hi,
I put all the infos into a gist, because the comments in Jira don't allow so many characters: https://gist.github.com/bastelfreak/4fd5f15f232d965480e21db7a5ef428b

let me know if you need more information

Matt Darcy (Jira)

unread,
Dec 2, 2020, 6:13:03 AM12/2/20
to puppe...@googlegroups.com
Matt Darcy updated an issue
 
Change By: Matt Darcy
Attachment: pi-puppet7-facter4-sshd-resource-output.rtf

Matt Darcy (Jira)

unread,
Dec 2, 2020, 6:22:03 AM12/2/20
to puppe...@googlegroups.com
Matt Darcy updated an issue
Change By: Matt Darcy
Attachment: pi-puppet6-facter4-sshd-resource-output.rtf

Matt Darcy (Jira)

unread,
Dec 2, 2020, 6:22:03 AM12/2/20
to puppe...@googlegroups.com
Matt Darcy commented on Bug FACT-2880
 
Re: facter 4 differing output from facter 3 for service_provider fact

debugging for Arm hosts uploaded as text documents.

Bogdan Irimie (Jira)

unread,
Dec 2, 2020, 7:02:05 AM12/2/20
to puppe...@googlegroups.com

Bogdan Irimie (Jira)

unread,
Dec 2, 2020, 11:32:04 AM12/2/20
to puppe...@googlegroups.com
Bogdan Irimie commented on Bug FACT-2880
 
Re: facter 4 differing output from facter 3 for service_provider fact

Tim Meusel and Matt Darcy we managed to reproduce the behaviour you describe by installing `puppet-prometheus` module. The custom fact https://github.com/voxpupuli/puppet-prometheus/blob/master/lib/facter/alert_manager_running.rb seams to generate the problem because it has code outside the `setcode` block. After moving 

service = Puppet::Type.type(:service).new(:name => 'alert_manager') # rubocop:disable Style/HashSyntax

inside the `setcode` block everything worked as expected.

Just as a test, please change the custom fact to

require 'puppet'
 
Facter.add('prometheus_alert_manager_running') do
  setcode do
    begin
      service = Puppet::Type.type(:service).new(:name => 'alert_manager') # rubocop:disable Style/HashSyntax
      service.provider.status == :running
    rescue Puppet::Error
      false
    end
  end
end

and let me know if it resolves the issue.

We will continue to investigate and come back to you once we have more info.

Bogdan Irimie (Jira)

unread,
Dec 2, 2020, 11:34:05 AM12/2/20
to puppe...@googlegroups.com

Tim Meusel (Jira)

unread,
Dec 2, 2020, 12:00:03 PM12/2/20
to puppe...@googlegroups.com
Tim Meusel commented on Bug FACT-2880
 
Re: facter 4 differing output from facter 3 for service_provider fact

awesome, I tested it locally and your patch works for me:

 ~ # puppet agent -t --environment puppet7
Info: Using configured environment 'puppet7'
Info: Retrieving pluginfacts
Info: Retrieving plugin
Notice: /File[/opt/puppetlabs/puppet/cache/lib/facter/alert_manager_running.rb]/content: 
--- /opt/puppetlabs/puppet/cache/lib/facter/alert_manager_running.rb	2020-11-04 16:45:06.270485994 +0100
+++ /tmp/puppet-file20201202-8312-olysy6	2020-12-02 17:56:41.113642951 +0100
@@ -1,10 +1,9 @@
 require 'puppet'
 
-service = Puppet::Type.type(:service).new(:name => 'alert_manager') # rubocop:disable Style/HashSyntax
-
 Facter.add('prometheus_alert_manager_running') do
   setcode do
     begin
+      service = Puppet::Type.type(:service).new(:name => 'alert_manager') # rubocop:disable Style/HashSyntax
       service.provider.status == :running
     rescue Puppet::Error
       false
 
Notice: /File[/opt/puppetlabs/puppet/cache/lib/facter/alert_manager_running.rb]/content: content changed '{sha256}518ae231be525cdc7a3ef433be324eca2b9a7ecd59c16e7099951fba54119c3e' to '{sha256}c9b384b194a462759e5aeeb8470c1261d5cb74dfe215844f7ce1a71d30b0f531'
Info: Loading facts
Info: Caching catalog for ***
Info: Applying configuration version '1606928210'
Notice: /Stage[main]/Puppet::Config/Concat[/etc/puppetlabs/puppet/puppet.conf]/File[/etc/puppetlabs/puppet/puppet.conf]/content: 
--- /etc/puppetlabs/puppet/puppet.conf	2020-12-02 17:54:52.243692525 +0100
+++ /tmp/puppet-file20201202-8312-1auouen	2020-12-02 17:57:07.085585360 +0100
@@ -17,7 +17,7 @@
 [agent]
     classfile = $statedir/classes.txt
     default_schedules = false
-    environment = production
+    environment = puppet7
     localconfig = $vardir/localconfig
     masterport = 8140
     noop = false
 
Info: Computing checksum on file /etc/puppetlabs/puppet/puppet.conf
Info: /Stage[main]/Puppet::Config/Concat[/etc/puppetlabs/puppet/puppet.conf]/File[/etc/puppetlabs/puppet/puppet.conf]: Filebucketed /etc/puppetlabs/puppet/puppet.conf to puppet with sum d12adcdb2659edab7d482ae3f2f5f6d50986f43ea3de075d0050a707eac29036
Notice: /Stage[main]/Puppet::Config/Concat[/etc/puppetlabs/puppet/puppet.conf]/File[/etc/puppetlabs/puppet/puppet.conf]/content: content changed '{sha256}d12adcdb2659edab7d482ae3f2f5f6d50986f43ea3de075d0050a707eac29036' to '{sha256}f2361f651546403e5dc4eefe7f89271cc42cde1aa0ccf71d8d843850dc7e427e'
Info: Class[Puppet::Config]: Scheduling refresh of Class[Puppet::Agent::Service]
Info: Class[Puppet::Agent::Service]: Scheduling refresh of Class[Puppet::Agent::Service::Daemon]
Info: Class[Puppet::Agent::Service]: Scheduling refresh of Class[Puppet::Agent::Service::Systemd]
Info: Class[Puppet::Agent::Service]: Scheduling refresh of Class[Puppet::Agent::Service::Cron]
Info: Class[Puppet::Agent::Service::Daemon]: Scheduling refresh of Service[puppet]
Notice: /Stage[main]/Puppet::Agent::Service::Daemon/Service[puppet]: Triggered 'refresh' from 1 event
Info: Class[Puppet::Agent::Service::Systemd]: Scheduling refresh of Exec[systemctl-daemon-reload-puppet]
Info: Class[Puppet::Agent::Service::Systemd]: Scheduling refresh of Service[puppet-run.timer]
Notice: /Stage[main]/Puppet::Agent::Service::Systemd/Service[puppet-run.timer]: Triggered 'refresh' from 1 event
Notice: /Stage[main]/Puppet::Agent::Service::Systemd/Exec[systemctl-daemon-reload-puppet]: Triggered 'refresh' from 1 event
Notice: Applied catalog in 14.28 seconds
 ~ # puppet resource service sshd 
service { 'sshd':
  ensure   => 'running',
  enable   => 'true',
  provider => 'systemd',
}
 ~ # 

should puppet be called within the setcode block? If so, I can patch the prometheus module.

Josh Cooper (Jira)

unread,
Dec 2, 2020, 12:57:04 PM12/2/20
to puppe...@googlegroups.com
Josh Cooper commented on Bug FACT-2880

It'd be great if there was a PDK lint rule to catch this. It's a pretty common error when writing custom facts. I'm not sure how feasible that is though? /cc David Schmitt

Josh Cooper (Jira)

unread,
Dec 2, 2020, 2:15:04 PM12/2/20
to puppe...@googlegroups.com

Bogdan Irimie (Jira)

unread,
Dec 3, 2020, 12:13:02 PM12/3/20
to puppe...@googlegroups.com
Bogdan Irimie commented on Bug FACT-2880
 
Re: facter 4 differing output from facter 3 for service_provider fact

Tim Meusel thanks for testing this!

After digging a little deeper we found that Facter 3 does not even load the custom fact files if no custom fact is requested. Facter 4 on the other hand always loads the custom facts, even if no custom fact was requested (we do this for multiple reasons, one of them is you might have a custom fact with the same name as a core facts but with a higher weight).

Because of this difference Facter 3 was not loading the custom fact file and Facter 4 was loading it when we were executing `puppet resource service sshd`. When we forced Facter 3 to load the file, we got the same behaviour as with Facter 4.

Regarding the placement of the code in custom fact, it should always be inside the `setcode` block.

Currently we are evaluating how we want to move forward, but once we reach a conclusion I will let you know.

Tim Meusel (Jira)

unread,
Dec 3, 2020, 12:17:04 PM12/3/20
to puppe...@googlegroups.com
Tim Meusel commented on Bug FACT-2880

thanks for the feedback. I fixed it in master for puppet-prometheus. I agree with Josh Cooper that a puppet-lint plugin might be really good here (although I think puppet-lint at the moment only checks actual Puppet DSL)

Bogdan Irimie (Jira)

unread,
Dec 7, 2020, 3:47:05 AM12/7/20
to puppe...@googlegroups.com
Bogdan Irimie assigned an issue to Unassigned
 
Change By: Bogdan Irimie
Assignee: Bogdan Irimie

David Schmitt (Jira)

unread,
Dec 7, 2020, 5:27:04 AM12/7/20
to puppe...@googlegroups.com
David Schmitt commented on Bug FACT-2880
 
Re: facter 4 differing output from facter 3 for service_provider fact

we have precedence of writing rubocop plugins for important issues.

Theoretically this should be quite easy to detect. cc Ben Ford for prioritisation.

Bogdan Irimie (Jira)

unread,
Dec 8, 2020, 3:51:03 AM12/8/20
to puppe...@googlegroups.com

Bogdan Irimie (Jira)

unread,
Dec 8, 2020, 3:51:03 AM12/8/20
to puppe...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages