12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 |
- require 'yaml'
- require 'popen4'
- STDOUT.sync = true
- task :default => :setup
- ##########################################################################
- def run_command(cmd)
- cmdrun = IO.popen(cmd)
- output = cmdrun.read
- cmdrun.close
- if $?.to_i > 0
- puts "count not run #{cmd}, it returned an error #{output}"
- exit 2
- end
- puts "OK: ran command #{cmd}"
- end
- ##########################################################################
- hf = Dir.glob('puppet/ext/data/common.yaml')
- errors = []
- desc 'Check Playbook Syntax'
- task :lint_hiera do
- hf.each do |playbook_file|
- begin
- YAML.load_file(playbook_file)
- rescue Exception => e
- errors << e.message
- end
- end
- if errors.empty?
- puts "Rake: #{hf.length} playbook files all checkout!"
- else
- errors.each do |err|
- puts "ERROR: YAML parse errors"
- puts err
- end
- exit 1
- end
- end
- ##########################################################################
- desc 'Check Prereqs'
- task :check_prereqs do
- [ 'rvm', 'bundler', 'r10k' ].each do |st|
- cmdrun = IO.popen("type -a #{st} >/dev/null 2>&1")
- cmdrun.close
- if $?.to_i > 0
- puts "Could not find binary #{st}"
- exit 2
- end
- end
- puts "OK: we have everything we need"
- end
- desc 'Update the Puppet Modules'
- task :update_puppet do
- puts 'Rake: updating puppet modules'
- run_command('cd puppet && rm -rf modules/* && r10k puppetfile install')
- end
- task :bundle_gems do
- run_command('bundle install')
- end
- task :bundler_install do
- run_command('gem install bundler')
- end
- desc 'Setup'
- task :setup => [:check_prereqs, :bundler_install, :bundle_gems, :update_puppet, :lint_hiera ] do
- puts 'Rake: Building the ami '
- end
|