-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rakefile
43 lines (39 loc) · 1.64 KB
/
Rakefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
require 'rake'
require 'rspec/core/rake_task'
require 'yaml'
require 'ansible_spec'
properties = AnsibleSpec.get_properties
# {"name"=>"Ansible-Sample-TDD", "hosts"=>["192.168.0.103","192.168.0.103"], "user"=>"root", "roles"=>["nginx", "mariadb"]}
# {"name"=>"Ansible-Sample-TDD", "hosts"=>[{"name" => "192.168.0.103:22","uri"=>"192.168.0.103","port"=>22, "private_key"=> "~/.ssh/id_rsa"}], "user"=>"root", "roles"=>["nginx", "mariadb"]}
desc "Run serverspec to all test"
task :all => "serverspec:all"
namespace :serverspec do
task :all => properties.map {|v| 'serverspec:' + v["name"] }
properties = properties.compact.reject{|e| e["hosts"].length == 0}
properties.each_with_index.map do |property, index|
property["hosts"].each do |host|
desc "Run serverspec for #{property["name"]}"
RSpec::Core::RakeTask.new(property["name"].to_sym) do |t|
puts "Run serverspec for #{property["name"]} to #{host}"
ENV['TARGET_HOSTS'] = host["hosts"]
ENV['TARGET_HOST'] = host["uri"]
ENV['TARGET_PORT'] = host["port"].to_s
ENV['TARGET_GROUP_INDEX'] = index.to_s
ENV['TARGET_PRIVATE_KEY'] = host["private_key"]
unless host["user"].nil?
ENV['TARGET_USER'] = host["user"]
else
ENV['TARGET_USER'] = property["user"]
end
ENV['TARGET_PASSWORD'] = host["pass"]
ENV['TARGET_CONNECTION'] = host["connection"]
roles = property["roles"]
for role in property["roles"]
deps = AnsibleSpec.load_dependencies(role)
roles += deps
end
t.pattern = 'roles/{' + roles.join(',') + '}/spec/*_spec.rb'
end
end
end
end