Detect how external “facts” are taken into consideration by “facter” :

root@puppet:~# facter --debug 2>&1 | grep "external facts"
2015-12-19 14:49:27.418534 DEBUG puppetlabs.facter - searching "/opt/puppetlabs/facter/facts.d" for external facts.
2015-12-19 14:49:27.419123 DEBUG puppetlabs.facter - searching "/etc/facter/facts.d" for external facts.
2015-12-19 14:49:27.419466 DEBUG puppetlabs.facter - skipping external facts for "/etc/puppetlabs/facter/facts.d": No such file or directory
2015-12-19 14:49:27.419680 DEBUG puppetlabs.facter - no external facts were found.

Create those directories :

root@puppet:~# mkdir -p /opt/puppetlabs/facter/facts.d /etc/facter/facts.d

Go to the first directory :

root@puppet:~# cd /opt/puppetlabs/facter/facts.d

Create this Ruby style “facts”¬†:

root@puppet:/etc/puppetlabs/facter/facts.d# cat default_gateway.rb
# in order to get the default gateway
Facter.add('default_gateway') do
  setcode do
    case Facter.value(:lsbdistid)
    when /Ubuntu|RedHat|Debian/
      Facter::Core::Execution.exec('/sbin/ip -4 route show match 0 | /usr/bin/awk \'{print $3}\'')
    end
  end
end

You can try this “facts” :

root@puppet:/etc/puppetlabs/facter/facts.d# facter --custom-dir=/etc/puppetlabs/facter/facts default_gateway
192.168.1.1

 

 

PDF Printer    Send article as PDF   

Leave a Reply

Your email address will not be published. Required fields are marked *


*