Custom facts in facter

36 views
Skip to first unread message

Hugo Deprez

unread,
Oct 21, 2015, 12:56:58 PM10/21/15
to puppet...@googlegroups.com
Hello,

I created a custom fact with the following procedure :

mkdir -p /etc/puppet/modules/facts/lib/facter
touch apache.rb

Content of apache.rb file :
Facter.add('apache') do
  setcode do
     apache_package = Facter::Core::Execution.exec('which apache2')
        
    # if 'which apache2' exits with an error, jruby_path will be an empty string
    if apache_package == ""
      false
    else
      true
    end
  end
end

this is working when I use the $apache in templates, but when I do :
#facter apache

I got an empty answer.

How can I add the value to facter ?

Best regards,

Hugo

Peter Bukowinski

unread,
Oct 21, 2015, 1:06:36 PM10/21/15
to puppet...@googlegroups.com
To load puppet-provided facts, you need to add the '-p' option. 'facter -p apache' should work.

--
Peter

Hugo Deprez

unread,
Oct 22, 2015, 8:15:03 AM10/22/15
to puppet...@googlegroups.com
Hello,

this is working.

Thank you !

Hugo


--
You received this message because you are subscribed to the Google Groups "Puppet Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to puppet-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/6A5B1F20-D1EC-4E30-B74A-5C1A22095A6C%40gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages