Cannot retrieve custom facts on some hosts

asked 2014-09-30 16:03:52 -0500

updated 2014-09-30 16:05:21 -0500

Hi all,

I have a rare anomaly where on some hosts, custom facts do not work. I am on PE 2.7. I get this error during puppet runs:

Could not retrieve colo_code: private method `chop' called for nil:NilClass

And with all messages leading up to the error:

info: Caching certificate for dbx01-sc9.virginam.com
info: Retrieving plugin
info: Caching certificate_revocation_list for ca
info: Loading facts in /var/opt/lib/pe-puppet/lib/facter/puppet_vardir.rb
info: Loading facts in /var/opt/lib/pe-puppet/lib/facter/facter_dot_d.rb
info: Loading facts in /var/opt/lib/pe-puppet/lib/facter/colo_code.rb
info: Loading facts in /var/opt/lib/pe-puppet/lib/facter/root_home.rb
Could not retrieve colo_code: private method `chop' called for nil:NilClass
Could not retrieve colo_code: private method `chop' called for nil:NilClass
info: Caching catalog for dbx01-sc9.virginam.com
info: Applying configuration version '1412110455'

The custom fact shows up on most nodes, as shown with facter -p

The configuration is the same on all hosts and the script used for the custom facts, colo_code.rb looks correct. Here is the script:

Facter.add("colo_code") do
    setcode do
        %x{/bin/hostname}[/(sc9|bgm|sac)\./].chop
    end
end
edit retag flag offensive close merge delete

Comments

Does this fail consistently, or is it OK on a re-run? If its OK on a second run of Puppet, could there be any environmental issues preventing /bin/hostname from running properly?

jonn gravatar imagejonn ( 2014-10-01 05:10:39 -0500 )edit

It fails consistently and running /bin/hostname works, yet your point made me realize that /bin/hostname only returns the short name on this host, but on other hosts it gives the fqdn. This might be the problem since the chop method is looking for a dot in the name. I will fix the fqdn and test.

Cornellio gravatar imageCornellio ( 2014-10-01 14:06:37 -0500 )edit

It turns out the solution was fixing the FQDN since setting the fact depends on a proper hostname being returned. Thanks.

Cornellio gravatar imageCornellio ( 2014-10-02 12:20:55 -0500 )edit