Last active
August 29, 2015 13:56
-
-
Save petems/8956030 to your computer and use it in GitHub Desktop.
Parse Puppet Rake file
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
source 'https://rubygems.org' | |
gem "puppet", "~> 3" | |
gem "highline" | |
gem "ruby-progressbar" | |
gem "rake" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Total Puppetfiles found 10 | |
Parsing with Puppet Version: 3.4.2 | |
Time: 00:00:00 <==================================================================================================================================================================================================================================================> 100% Parsing | |
10 files total. | |
10 files succeeded. | |
0 files failed. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rake' | |
require 'rake/tasklib' | |
require 'highline/import' | |
require 'ruby-progressbar' | |
require 'puppet' | |
desc "Parse puppet files" | |
task :parse do | |
puppet_file_list = FileList['**/*.pp'] | |
successes = 0 | |
failures = 0 | |
error_string = "" | |
say "Total Puppetfiles found #{puppet_file_list.length}" | |
if Integer(Puppet.version.split('.').first) >= 3 | |
Puppet.initialize_settings | |
end | |
puts "Parsing with Puppet Version: #{Puppet.version}" | |
parse_progress = ProgressBar.create(:title => "Parsing", :format => '%a <%B> %p%% %t', | |
:starting_at => 0, :total => puppet_file_list.length) | |
puppet_file_list.each_with_index do |puppet_file, index| | |
parse_progress.increment | |
begin | |
parser = Puppet::Parser::Parser.new("rake-parse-#{index}") | |
parser.import("#{File.expand_path(puppet_file)}") | |
successes += 1 | |
rescue Puppet::ParseError => e | |
error_string += "Parse Error on #{puppet_file}: #{e.message}\n" | |
failures += 1 | |
end | |
end | |
total_manifests = successes + failures | |
say "#{total_manifests} files total." | |
say "#{successes} files succeeded." | |
say "#{failures} files failed." | |
if failures > 0 | |
say "#{error_string}" | |
fail "#{failures} puppet files failed syntax check." | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment