Jira (FACT-3200) Facter throws ``Error while resolving custom fact fact='<module_name>'``

6 views
Skip to first unread message

Gavin Didrichsen (Jira)

unread,
May 4, 2023, 4:00:07 AM5/4/23
to puppe...@googlegroups.com
Gavin Didrichsen created an issue
 
Facter / Bug FACT-3200
Facter throws ``Error while resolving custom fact fact='<module_name>'``
Issue Type: Bug Bug
Assignee: Unassigned
Created: 2023/05/04 1:00 AM
Priority: Normal Normal
Reporter: Gavin Didrichsen

When I run a plan against nodes on GCP, I always see the following non-fatal error:

Facter throws ``Error while resolving custom fact fact='<module_name>'`

See replication and workaround in Description section.

Desired Behaviour

  Notice: /Stage[main]/Main/Notify[Hello, world!]/message: defined 'message' as 'Hello, world!'
  changed: 1, failed: 0, unchanged: 0 skipped: 0, noop: 0

Actual Behaviour

  Err: Facter: Error while resolving custom fact fact='usage', resolution='<anonymous>': No such file or directory @ rb_sysopen - /etc/puppetlabs/puppet/ssl/private_keys/cd4pe01-9c8d30-0.us-west1-c.c.customer-support-scratchpad.internal.pem
  Notice: /Stage[main]/Main/Notify[Hello, world!]/message: defined 'message' as 'Hello, world!'
  changed: 1, failed: 0, unchanged: 0 skipped: 0, noop: 0

Description

On 1 of 3 nodes with only puppet installed, i.e., not enrolled with a primary PE:

root@cd4pe01-9c8d30-0 usage (development)$ hostname -f
cd4pe01-9c8d30-0.us-west1-c.c.customer-support-scratchpad.internal
root@cd4pe01-9c8d30-0 usage (development)$ puppet --version
7.24.0
root@cd4pe01-9c8d30-0 usage (development)$ facter --version
4.3.1
root@cd4pe01-9c8d30-0 usage (development)$ 

Given the following ``usage::dummy`` plan beneath my ``usage`` module and a bolt inventory of 3 GCP nodes (not enrolled with any PE primary):

root@cd4pe01-9c8d30-0 usage (development)$ cat plans/dummy.pp 
# @summary A dummy plan for testing small changes
# @param targets The targets to run on.
plan usage::dummy (
  TargetSpec $targets = 'localhost',
) {
  apply_prep($targets)
  apply($targets) {
    notify { 'Hello, world!': }
  }
}
root@cd4pe01-9c8d30-0 usage (development)$ bolt inventory show
The project 'usage' shadows an existing module of the same name [ID: project_shadows_module]
Targets
  cd4pe01-9c8d30-0.us-west1-c.c.customer-support-scratchpad.internal
  cd4pestand-9c8d30-0.us-west1-c.c.customer-support-scratchpad.internal
  scd4pe-9c8d30-0.us-west1-c.c.customer-support-scratchpad.internal
 
Inventory source
  /root/development/tools/puppet/@usage/modules/gavin/usage/inventory.yaml
 
Target count
  3 total, 3 from inventory, 0 adhoc
 
Additional information
  Use the '--targets', '--query', or '--rerun' option to view specific targets
  Use the '--detail' option to view target configuration and data

When I run the plan from my ``usage`` module root I see a non-fatal error for each node like this:

Finished on cd4pe01-9c8d30-0.us-west1-c.c.customer-support-scratchpad.internal:
  Err: Facter: Error while resolving custom fact fact='usage', resolution='<anonymous>': No such file or directory @ rb_sysopen - /etc/puppetlabs/puppet/ssl/private_keys/cd4pe01-9c8d30-0.us-west1-c.c.customer-support-scratchpad.internal.pem

and shown in more detail like this for all 3 nodes:

root@cd4pe01-9c8d30-0 usage (development)$ /opt/puppetlabs/bin/bolt plan run usage::dummy --targets=all --verbose
Starting: plan usage::dummy
Starting: install puppet and gather facts on cd4pe01-9c8d30-0.us-west1-c.c.customer-support-scratchpad.internal, cd4pestand-9c8d30-0.us-west1-c.c.customer-support-scratchpad.internal, scd4pe-9c8d30-0.us-west1-c.c.customer-support-scratchpad.internal
Finished: install puppet and gather facts with 0 failures in 7.06 sec
Starting: apply catalog on cd4pe01-9c8d30-0.us-west1-c.c.customer-support-scratchpad.internal, cd4pestand-9c8d30-0.us-west1-c.c.customer-support-scratchpad.internal, scd4pe-9c8d30-0.us-west1-c.c.customer-support-scratchpad.internal
Started on cd4pe01-9c8d30-0.us-west1-c.c.customer-support-scratchpad.internal...
Started on cd4pestand-9c8d30-0.us-west1-c.c.customer-support-scratchpad.internal...
Started on scd4pe-9c8d30-0.us-west1-c.c.customer-support-scratchpad.internal...
Finished on cd4pe01-9c8d30-0.us-west1-c.c.customer-support-scratchpad.internal:
  Err: Facter: Error while resolving custom fact fact='usage', resolution='<anonymous>': No such file or directory @ rb_sysopen - /etc/puppetlabs/puppet/ssl/private_keys/cd4pe01-9c8d30-0.us-west1-c.c.customer-support-scratchpad.internal.pem
  Notice: /Stage[main]/Main/Notify[Hello, world!]/message: defined 'message' as 'Hello, world!'
  changed: 1, failed: 0, unchanged: 0 skipped: 0, noop: 0
Finished on scd4pe-9c8d30-0.us-west1-c.c.customer-support-scratchpad.internal:
  Err: Facter: Error while resolving custom fact fact='usage', resolution='<anonymous>': No such file or directory @ rb_sysopen - /etc/puppetlabs/puppet/ssl/private_keys/scd4pe-9c8d30-0.us-west1-c.c.customer-support-scratchpad.internal.pem
  Notice: /Stage[main]/Main/Notify[Hello, world!]/message: defined 'message' as 'Hello, world!'
  changed: 1, failed: 0, unchanged: 0 skipped: 0, noop: 0
Finished on cd4pestand-9c8d30-0.us-west1-c.c.customer-support-scratchpad.internal:
  Err: Facter: Error while resolving custom fact fact='usage', resolution='<anonymous>': No such file or directory @ rb_sysopen - /etc/puppetlabs/puppet/ssl/private_keys/cd4pestand-9c8d30-0.us-west1-c.c.customer-support-scratchpad.internal.pem
  Notice: /Stage[main]/Main/Notify[Hello, world!]/message: defined 'message' as 'Hello, world!'
  changed: 1, failed: 0, unchanged: 0 skipped: 0, noop: 0
Finished: apply catalog with 0 failures in 11.76 sec
Finished: plan usage::dummy in 18.83 sec
Plan completed successfully with no result

However, if I add a simple external fact to one of the nodes ``cd4pe01-9c8d30-0`` as follows

root@cd4pe01-9c8d30-0 usage (development)$ cat /opt/puppetlabs/facter/facts.d/usage.sh 
#!/bin/sh
 
echo "usage='hello world'"
root@cd4pe01-9c8d30-0 usage (development)$ 

Then the error disappears for the ``cd4pe01-9c8d30-0`` node, e.g.,

root@cd4pe01-9c8d30-0 usage (development)$ pbpr dummy --targets=all
/opt/puppetlabs/bin/bolt plan run usage::dummy --targets=all --verbose
Starting: plan usage::dummy
Starting: install puppet and gather facts on cd4pe01-9c8d30-0.us-west1-c.c.customer-support-scratchpad.internal, cd4pestand-9c8d30-0.us-west1-c.c.customer-support-scratchpad.internal, scd4pe-9c8d30-0.us-west1-c.c.customer-support-scratchpad.internal
Finished: install puppet and gather facts with 0 failures in 6.2 sec
Starting: apply catalog on cd4pe01-9c8d30-0.us-west1-c.c.customer-support-scratchpad.internal, cd4pestand-9c8d30-0.us-west1-c.c.customer-support-scratchpad.internal, scd4pe-9c8d30-0.us-west1-c.c.customer-support-scratchpad.internal
Started on cd4pe01-9c8d30-0.us-west1-c.c.customer-support-scratchpad.internal...
Started on scd4pe-9c8d30-0.us-west1-c.c.customer-support-scratchpad.internal...
Started on cd4pestand-9c8d30-0.us-west1-c.c.customer-support-scratchpad.internal...
Finished on cd4pestand-9c8d30-0.us-west1-c.c.customer-support-scratchpad.internal:
  Err: Facter: Error while resolving custom fact fact='usage', resolution='<anonymous>': No such file or directory @ rb_sysopen - /etc/puppetlabs/puppet/ssl/private_keys/cd4pestand-9c8d30-0.us-west1-c.c.customer-support-scratchpad.internal.pem
  Notice: /Stage[main]/Main/Notify[Hello, world!]/message: defined 'message' as 'Hello, world!'
  changed: 1, failed: 0, unchanged: 0 skipped: 0, noop: 0
Finished on cd4pe01-9c8d30-0.us-west1-c.c.customer-support-scratchpad.internal:
  Notice: /Stage[main]/Main/Notify[Hello, world!]/message: defined 'message' as 'Hello, world!'
  changed: 1, failed: 0, unchanged: 0 skipped: 0, noop: 0
Finished on scd4pe-9c8d30-0.us-west1-c.c.customer-support-scratchpad.internal:
  Err: Facter: Error while resolving custom fact fact='usage', resolution='<anonymous>': No such file or directory @ rb_sysopen - /etc/puppetlabs/puppet/ssl/private_keys/scd4pe-9c8d30-0.us-west1-c.c.customer-support-scratchpad.internal.pem
  Notice: /Stage[main]/Main/Notify[Hello, world!]/message: defined 'message' as 'Hello, world!'
  changed: 1, failed: 0, unchanged: 0 skipped: 0, noop: 0
Finished: apply catalog with 0 failures in 11.08 sec
Finished: plan usage::dummy in 17.3 sec
Plan completed successfully with no result
root@cd4pe01-9c8d30-0 usage (development)$ 

I'd like to be able to run the plan without having to place an external fact as a workaround.

Add Comment Add Comment
 
This message was sent by Atlassian Jira (v8.20.11#820011-sha1:0629dd8)
Atlassian logo

Josh Cooper (Jira)

unread,
May 4, 2023, 11:01:02 AM5/4/23
to puppe...@googlegroups.com
Josh Cooper commented on Bug FACT-3200
 
Re: Facter throws ``Error while resolving custom fact fact='<module_name>'``

Facter on its own won't try to load /etc/puppetlabs/puppet/ssl/private_keys/scd4pe-9c8d30-0.us-west1-c.c.customer-support-scratchpad.internal.pem. I'm guessing this is coming from another fact. Can you run with "facter usage --trace --debug" and include/attach the stack trace?

Gavin Didrichsen (Jira)

unread,
May 4, 2023, 2:29:03 PM5/4/23
to puppe...@googlegroups.com

Hi Josh Cooper.

You're absolutely right...sorry for the false alarm here.

I didn't realize that this module had a custom fact that was expecting the presence of ``/etc/puppetlabs/puppet/ssl/private_keys/#

{Puppet.settings[:certname]}

.pem'``. Once the File.exists?() check was added then the error went away.

require 'puppet'
require 'yaml'
require 'net/ssh'
 
Facter.add(:usage, type: :aggregate) do
  chunk(:sshkey) do
    private_key_file = File.join('/etc/puppetlabs/puppet/ssl/private_keys', Puppet.settings[:certname] + '.pem')
    identifier = Puppet.settings[:certname]
 
    if File.exists?(private_key_file)
      key = OpenSSL::PKey::RSA.new(File.read(private_key_file))
      type = key.ssh_type
      data = [ key.to_blob ].pack('m0')
    else
      type = "no type because '/etc/puppetlabs/puppet/ssl/private_keys/#{Puppet.settings[:certname]}.pem' doesn't exist" 
      data = "no public sshkey because '/etc/puppetlabs/puppet/ssl/private_keys/#{Puppet.settings[:certname]}.pem' doesn't exist" 
    end
 
    # return the OpenSSH public SSHKey
    { sshkey: {
      type: type.chomp,
        key: data.chomp,
        identifier: identifier.chomp,
    } }
  end
end

Gavin Didrichsen (Jira)

unread,
May 4, 2023, 2:30:03 PM5/4/23
to puppe...@googlegroups.com
Gavin Didrichsen assigned an issue to Josh Cooper
 
Change By: Gavin Didrichsen
Assignee: Josh Cooper
Resolution: Fixed
Status: Open Resolved
Reply all
Reply to author
Forward
0 new messages