Last active
September 13, 2015 11:53
-
-
Save muziyoshiz/d532f5451bc5b8303a99 to your computer and use it in GitHub Desktop.
Serverspec Rakefile creating tasks from Ansible inventory
This file contains 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 'rspec/core/rake_task' | |
# Sample of Ansible groups and hosts | |
# http://docs.ansible.com/ansible/intro_inventory.html | |
groups = {} | |
groups["webservers"] = [ "foo.example.com", "bar.example.com" ] | |
groups["dbservers"] = [ "one.example.com", "two.example.com", "three.example.com" ] | |
task :spec => 'spec:all' | |
task :default => :spec | |
namespace :spec do | |
task :all => groups.keys.map {|group| 'spec:' + group } | |
task :default => :all | |
# Tasks for groups | |
groups.keys.each do |group| | |
task group.to_sym => groups[group].map {|host| 'spec:' + group + ':' + host } | |
groups[group].each do |host| | |
desc "Run tests for group '#{group}'" | |
task_name = group + ':' + host | |
RSpec::Core::RakeTask.new(task_name) do |t| | |
ENV['TARGET_HOST'] = host | |
t.pattern = "spec/#{group}/*_spec.rb" | |
end | |
end | |
end | |
# Tasks for hosts without groups | |
groups.values.flatten.uniq.each do |host| | |
desc "Run tests for host '#{host}'" | |
RSpec::Core::RakeTask.new(host) do |t| | |
ENV['TARGET_HOST'] = host | |
t.pattern = "spec/hosts/#{host}/*_spec.rb" | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment