(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.)