0

Suppose I have a module in puppet that creates custom facts. But to do so, it requires a package package_a to be installed. Based on whether this package is there or not it will decide to generate the facts.

This package is installed as part of the puppet run in a profile. So initially the facts will not be generated from the module.

Once the package is installed that is used to generate the custom facts, is there any way to notify puppet to gather these facts so it can be used in following profiles?

The module that adds the custom facts:

Facter.add(:custom_facts) do
  confine do
    exists = Facter::Core::Execution.which('package_a') != nil
    Puppet.debug "Testing custom_facts fact applicable? #{exists.inspect}"
    true
  end

  setcode do
    to_ret = {}
    result = JSON.parse(Facter::Core::Execution.execute('package_a some command'))
    Puppet.debug "Facts returned by command: #{result.inspect}"
    result.each do |key,value|
      to_ret[key]={
        'value'   => value['value'],
      }
    end
    to_ret
  end
end
leoOrion
  • 1,833
  • 2
  • 26
  • 52
  • That would involve re-pluginsyncing and/or re-compiling the catalog during catalog application. You should probably try a different route here. On the other hand, if you are talking about utilizing the custom fact for a subsequent application, then you are fine. It is unclear what usage you are inquiring about in your question. – Matthew Schuchard Oct 19 '18 at 15:49
  • Using the custom fact in the same run not the next subsequent one. – leoOrion Oct 19 '18 at 15:58
  • Then this is probably not possible. – Matthew Schuchard Oct 19 '18 at 17:13

0 Answers0