Rakefile 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. require 'yaml'
  2. require 'popen4'
  3. STDOUT.sync = true
  4. task :default => :build_full_ami
  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('ansible/playbook.yml')
  18. errors = []
  19. desc 'Check Playbook Syntax'
  20. task :lint_playbook 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 'Update the Galaxy Modules'
  40. task :update_galaxy do
  41. puts 'Rake: updating galaxy modules'
  42. run_command('cd ansible && rm -rf roles/* && ansible-galaxy install --roles-path roles -r requirements.yml')
  43. end
  44. task :validate_packer do
  45. puts 'Rake: validating packer.json'
  46. run_command('packer validate packer.json')
  47. end
  48. task :build_ami do
  49. puts 'Rake: Building ami'
  50. POpen4::popen4( "packer build packer.json" ) do |stdout, stderr, stdin|
  51. stdout.each do |line|
  52. puts line
  53. end
  54. end
  55. end
  56. desc 'Build the ami'
  57. task :build_full_ami => [:validate_packer, :update_galaxy, :lint_playbook, :build_ami] do
  58. puts 'Rake: Building the ami '
  59. end