Rakefile 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. require 'yaml'
  2. require 'popen4'
  3. STDOUT.sync = true
  4. task :default => :setup
  5. ##########################################################################
  6. def run_command(cmd)
  7. cmdrun = IO.popen(cmd)
  8. output = cmdrun.read
  9. cmdrun.close
  10. if $?.to_i > 0
  11. puts "count not run #{cmd}, it returned an error #{output}"
  12. exit 2
  13. end
  14. puts "OK: ran command #{cmd}"
  15. end
  16. ##########################################################################
  17. hf = Dir.glob('puppet/ext/data/common.yaml')
  18. errors = []
  19. desc 'Check Playbook Syntax'
  20. task :lint_hiera do
  21. hf.each do |playbook_file|
  22. begin
  23. YAML.load_file(playbook_file)
  24. rescue Exception => e
  25. errors << e.message
  26. end
  27. end
  28. if errors.empty?
  29. puts "Rake: #{hf.length} playbook files all checkout!"
  30. else
  31. errors.each do |err|
  32. puts "ERROR: YAML parse errors"
  33. puts err
  34. end
  35. exit 1
  36. end
  37. end
  38. ##########################################################################
  39. desc 'Check Prereqs'
  40. task :check_prereqs do
  41. [ 'rvm', 'bundler', 'r10k' ].each do |st|
  42. cmdrun = IO.popen("type -a #{st} >/dev/null 2>&1")
  43. cmdrun.close
  44. if $?.to_i > 0
  45. puts "Could not find binary #{st}"
  46. exit 2
  47. end
  48. end
  49. puts "OK: we have everything we need"
  50. end
  51. desc 'Update the Puppet Modules'
  52. task :update_puppet do
  53. puts 'Rake: updating puppet modules'
  54. run_command('cd puppet && rm -rf modules/* && r10k puppetfile install')
  55. end
  56. task :bundle_gems do
  57. run_command('bundle install')
  58. end
  59. task :bundler_install do
  60. run_command('gem install bundler')
  61. end
  62. desc 'Setup'
  63. task :setup => [:check_prereqs, :bundler_install, :bundle_gems, :update_puppet, :lint_hiera ] do
  64. puts 'Rake: Building the ami '
  65. end