How do I make puppet post facts after run?

I am using a simple puppet setup for a large number of servers. Puppet gets information from a CMDB using External Node Classifiers. This works perfectly.

After each run, the Puppet master posts the status for the run to the CMDB using a custom report module. This also works great.

What I would like is Puppet to post the facts for a node after each run to the CMDB. Doing this, the CMDB could auto update things like memory, MAC address etc.

The question is; How can I achieve this?

The report mechanism only provides status and some metrics.

It's not so easy to write a custom storeconfig module (or at least I couldn't find any information regarding this).

Thanks for any help.


I created a report module in Puppet that solved this particular use case. The reporter tries to read the latest yaml report then add extra stuff to the post.

  def process
    payload = { :host => self.host, :status => self.status, :kind => self.kind }   
    # if facts file found, read it and add facts to payload:
    if File.exists?("#{Puppet[:vardir]}/yaml/facts/#{self.host}.yaml")
        new_facts = {}
        node_facts = YAML.load_file("#{Puppet[:vardir]}/yaml/facts/#{self.host}.yaml")
        node_facts.values.each do |key, value|
            new_facts = new_facts.merge({key => value})
        end
        payload = payload.merge(new_facts)
    end    
    response = HTTParty.post(URL, :body => payload )
    Puppet.err "Response code: #{response.code} - #{response.body}" unless response.code == 200
  end

If you want to learn more about writing custom Puppet reports, check When Puppet reports part 2


Do you have a hard requirement to have it in the single CMDB, or is the goal just to have it queryable? PuppetDB already provides an API for facts lookup:

https://puppet.com/docs/puppetdb/latest/api/query/v4/facts.html

Strictly speaking, Puppet itself doesn't know what the value of facts are at the end of the run -- only at the beginning of the run. I'm not sure what your endgame is, but since Puppet is not itself tied to the value of your facts in any way, a better solution is probably to use MCollective rather than Puppet to aggregate details about your nodes, and store them using a custom registration plugin that posts back to your CMDB.