问题原文
原帖链接 · magnusa · CC BY-SA 3.0
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.
已采纳解答
原帖链接 · magnusa · CC BY-SA 3.0
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
摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。
