puppet_settings.rb 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. # These facter facts return the value of the Puppet vardir and environment path
  2. # settings for the node running puppet or puppet agent. The intent is to
  3. # enable Puppet modules to automatically have insight into a place where they
  4. # can place variable data, or for modules running on the puppet master to know
  5. # where environments are stored.
  6. #
  7. # The values should be directly usable in a File resource path attribute.
  8. #
  9. begin
  10. require 'facter/util/puppet_settings'
  11. rescue LoadError => e
  12. # puppet apply does not add module lib directories to the $LOAD_PATH (See
  13. # #4248). It should (in the future) but for the time being we need to be
  14. # defensive which is what this rescue block is doing.
  15. rb_file = File.join(File.dirname(__FILE__), 'util', 'puppet_settings.rb')
  16. load rb_file if File.exist?(rb_file) || raise(e)
  17. end
  18. # These will be nil if Puppet is not available.
  19. Facter.add(:puppet_vardir) do
  20. setcode do
  21. Facter::Util::PuppetSettings.with_puppet do
  22. Puppet[:vardir]
  23. end
  24. end
  25. end
  26. Facter.add(:puppet_environmentpath) do
  27. setcode do
  28. Facter::Util::PuppetSettings.with_puppet do
  29. Puppet[:environmentpath]
  30. end
  31. end
  32. end
  33. Facter.add(:puppet_server) do
  34. setcode do
  35. Facter::Util::PuppetSettings.with_puppet do
  36. Puppet[:server]
  37. end
  38. end
  39. end