Ruby post-commit script for puppet repos
#!/usr/bin/env ruby | |
# -*- coding: utf-8 -*- | |
# | |
# Parse all manifests. Send notification if errors exist. | |
# | |
# author: Thomas Van Doren | |
require 'puppet/face' | |
# Email sending config | |
SEND_MAIL=false | |
SMTP_HOST='localhost' | |
RECIPIENTS='' | |
busted_manifests = [] | |
errors = [] | |
# Iterate through all manifests, recording which ones fail. | |
Dir.glob('**/{manifests,tests}/**/*.pp').each do |manifest| | |
pparse = Puppet::Face['parser', :current] | |
begin | |
pparse.validate(manifest) | |
rescue Puppet::Error => e | |
busted_manifests << manifest | |
errors << e.to_s | |
end | |
end | |
if not busted_manifests.empty? | |
subject = "#{busted_manifests.length} busted manifests..." | |
body = busted_manifests.join(', ') + "\n\n" + errors.join("\n\n") | |
puts subject + "\n\n" + body + "\n" | |
if SEND_MAIL | |
# Send some email. | |
require 'net/smtp' | |
require 'socket' | |
sender = "repo@#{Socket.gethostname}" | |
message = <<EOM | |
From: #{sender} | |
To: #{RECIPIENTS} | |
Subject: #{subject} | |
#{body} | |
EOM | |
Net::SMTP.start(SMTP_HOST) do |smtp| | |
smtp.send_message message, sender, RECIPIENTS | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment