https://github.com/wikimedia/operations-puppet
Raw File
Tip revision: 8bcdb0bbae059c8a08f75c46da79e1d70b45ceef authored by Faidon Liambotis on 19 November 2012, 17:17:41 UTC
secure.wikimedia.org: add redirect for /w/
Tip revision: 8bcdb0b
rakefile
=begin
This rakefile is meant to trigger your local puppet-linter. To take
advantage of that powerful linter, you must have the puppet and
puppet-lint gems:

  $ sudo gem install puppet
  $ sudo gem instlal puppet-lint

Then run the linter using rake (a ruby build helper):

  $ rake lint

A list of top errors can be obtained using:
  rake lint |rev |cut -d\  -f4- | rev | sort | uniq -c | sort -rn

puppet-lint doc is at https://github.com/rodjek/puppet-lint

 -- hashar 20120216
=end

# Only care about color when using a tty
if Rake.application.tty_output?
	# Since we are going to use puppet internal stuff, we might as
	# well reuse their colorization utility:
	require'puppet/util/colors'
	include Puppet::Util::Colors

	puppetcolor = '--color true'
else
	# define our own colorization method that simply output the message
	def console_color( level, message )
		return message
	end

	puppetcolor = '--color none'
end

task :default => [:help]

desc 'Show the help'
task :help do
	puts "Puppet helper for operations/puppet.git

Welcome #{ENV['USER']} in WMF wonderful rake helper to play with puppet.

---[Command line options]----------------------------------------------
`rake -T` : list available tasks
`rake -P` : shows tasks dependencies

---[Available rake tasks]----------------------------------------------"

	# show our tasks list
	system "rake -T"

puts "-----------------------------------------------------------------------"
puts "
Examples:

Validate syntax for all puppet manifests:
  rake validate

Validate manifests/nfs.pp and manifests/apaches.pp
  rake \"validate[manifests/nfs.pp manifests/apaches.pp]\"

Run puppet style checker:
  rake lint
"

end

task :run_puppet_lint do
	require 'puppet-lint/tasks/puppet-lint'

	# Get possible checks values with: puppet-lint --help
	disabled_checks = [

		# We still use the 2.6 way of referencing variables.
		# 2.8 will requires $::globalname. Skip for now
		"variable_scope",

		# We really like nesting classes:
		"nested_classes_or_defines",

		# Lot of long lines (ssh keys for example)
		"80chars",

		# Anyone as a different indentation preference
		"hard_tabs",

		# Misc rules, some of them might use to be enabled later
		"autoloader_layout",  # unused in our setup?
		"inherits_across_namespaces",
		"double_quoted_strings",
		"unquoted_file_mode",
		"ensure_first_param",
		"unquoted_resource_title",

		# FIXME Following test cause a stacktrace ;-(
		"ensure_not_symlink_target",
	]

	# Disable checks referenced above:
	disabled_checks.each { |name|
		warn "Disabling rule '#{name}' from rakefile"
		PuppetLint.configuration.send( "disable_#{name}" )
	}
end

desc "Lint puppet files"
task :lint => :run_puppet_lint

desc "Validate puppet syntax (default: manifests/site.pp)"
task :validate, [:files ] do |t, args|
	args.with_defaults( :files => 'manifests/site.pp' )
	puts console_color( :info, "Validating " + args.files.inspect )
	sh "puppet parser validate #{puppetcolor} #{args.files}" do |ok, res|
		if ok
			puts "[OK] " + console_color( :info,  "files looks fine!" )
		else
			puts console_color( :alert, "puppet failed to validate files (exit: #{res.exitstatus}" )
		end
	end
end

=begin lint
amass profit
donate!
=end
back to top