facter external fact tips?

522 views
Skip to first unread message

Christopher Wood

unread,
Jan 8, 2015, 5:03:12 PM1/8/15
to puppet...@googlegroups.com
(As background, I am attempting to create an is/oos toggle, for servers, in facter. Before I file bugs on two oddities, maybe somebody here could tell me if I'm misunderstanding something. I am using facter 2.3.0 from the puppetlabs apt/yum repositories, required from an external ruby script. I have confirmed no rvm/gem/etc. in my $PATH.)


1) how do I get booleans out of external facts?

With a custom fact I can use an unquoted true to get a TrueFalse, or quote the "true" to get a String. With an external fact the true is always a string. Is there some way to get a boolean from an external fact without turning a true/false/on/off string into a boolean in my script code?

(It's a bug if facter is supposed to do magic with external fact values, but that magic concept sounds a bit fishy.)

Example:

root@cwl:~# cat /var/lib/puppet/lib/facter/truefalseone.rb
Facter.add(:truefalseone) do
setcode do
this="true"
end
end
root@cwl:~# cat /etc/facter/facts.d/truefalsetwo.txt
truefalsetwo=true
root@cwl:~# cat /tmp/cw2.rb
#!/usr/bin/env ruby

require 'facter'

# https://groups.google.com/forum/#!topic/puppet-users/DV_tzOvPRSw
ENV['FACTERLIB'] = "/var/lib/puppet/lib/facter"

puts 'class of truefalseone custom fact: ' + Facter.value(:truefalseone).class.to_s
puts 'class of truefalsetwo external fact: ' + Facter.value(:truefalsetwo).class.to_s

root@cwl:~# ruby /tmp/cw2.rb
class of truefalseone custom fact: String
class of truefalsetwo external fact: String


2) command line facter doesn't understand pluginsync'ed external facts

It's fine if I specify --external-dir on the command line, but not otherwise. Example:


root@cwl:~# cat /etc/facter/facts.d/truefalsetwo.txt
truefalsetwo=true
root@cwl:~# facter truefalsetwo
true
root@cwl:~# mv /etc/facter/facts.d/truefalsetwo.txt /var/lib/puppet/facts.d/
root@cwl:~# facter truefalsetwo

root@cwl:~# facter -p truefalsetwo

root@cwl:~# facter --external-dir /var/lib/puppet/facts.d truefalsetwo
true

It looks like in https://github.com/puppetlabs/facter/blob/master/lib/facter/util/config.rb the @external_facts_dirs needs another entry?

Maybe there's an EXTFACTERLIB sort of dir to work like FACTERLIB? (Couldn't find one.)

Felix Frank

unread,
Jan 11, 2015, 7:01:39 PM1/11/15
to puppet...@googlegroups.com
Hi,

On 01/08/2015 11:02 PM, Christopher Wood wrote:
> root@cwl:~# cat /etc/facter/facts.d/truefalsetwo.txt
> truefalsetwo=true

I think it's fine for this one to return a string. After all, the output
of a script is just text. Converting to boolean would be trivial, but
less so for arrays, hashes etc. Having no conversion at all is a
consistent choice.

> root@cwl:~# facter -p truefalsetwo
>
> root@cwl:~# facter --external-dir /var/lib/puppet/facts.d truefalsetwo
> true

I noticed that before, but paid it no mind - `facter -p | grep
^truefalsetwo`. Not pretty but usually sufficient.

It would be nice to have a bug report for this, anyway :-)

Cheers,
Felix
Reply all
Reply to author
Forward
0 new messages