Last active
August 29, 2015 14:07
-
-
Save rrreeeyyy/84efc2907814c56a2b4a to your computer and use it in GitHub Desktop.
itamae-serverspec Rakefile
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 'json' | |
require 'rspec/core/rake_task' | |
properties_file = 'properties.json' | |
properties = JSON.parse(File.read(properties_file)) | |
properties.keys.each do |key| | |
namespace :itamae do | |
desc "Run provision to #{key}" | |
task key => properties[key]['roles'].map {|r| [key, r].join(':') } | |
properties[key]['roles'].each do |role| | |
desc "Run itamae to #{key}:#{role}" | |
task [key, role].join(':') do | |
ENV['TARGET_HOST'] = key | |
options = Net::SSH::Config.for(key) | |
command = "bundle exec itamae ssh" | |
command << " -h #{key}" | |
command << " -u #{properties[key]['ssh_user'] || options[:user] || ENV['USER']}" | |
command << " -i #{properties[key]['private_key'] || options[:keys].first || '~/.ssh/id_rsa'}" | |
command << " -p #{properties[key]['ssh_port'] || options[:port] || 22}" | |
command << " -j #{properties_file || 'properties.json'}" | |
command << " recipes/#{role}/#{role}.rb" | |
puts command | |
system command | |
end | |
end | |
end | |
namespace :serverspec do | |
desc "Run serverspec to #{key}" | |
task key => properties[key]['roles'].map {|r| [key, r].join(':') } | |
properties[key]['roles'].each do |role| | |
desc "Run serverspec to #{key}:#{role}" | |
RSpec::Core::RakeTask.new([key, role].join(':')) do |t| | |
ENV['TARGET_HOST'] = key | |
t.pattern = 'spec/{' + role + '}/*_spec.rb' | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment