forked from volanja/ansible-sample-tdd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rakefile
35 lines (32 loc) · 1.31 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
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"]}
namespace :serverspec do
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_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
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