2022-07-02 19:58:59 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'rake'
|
|
|
|
require 'rspec/core/rake_task'
|
2022-07-02 22:26:54 +00:00
|
|
|
require_relative 'spec/ansible_inventory'
|
2022-07-02 19:58:59 +00:00
|
|
|
require 'pry'
|
|
|
|
|
|
|
|
task spec: 'spec:all'
|
|
|
|
task default: :spec
|
|
|
|
|
2022-07-02 22:26:54 +00:00
|
|
|
AnsibleInventory.read
|
|
|
|
|
2022-07-02 19:58:59 +00:00
|
|
|
namespace :spec do
|
|
|
|
desc 'Run serverspec'
|
2022-07-02 22:26:54 +00:00
|
|
|
task all: (AnsibleInventory.groups.map do |group|
|
2022-07-02 19:58:59 +00:00
|
|
|
"#{group}:all"
|
|
|
|
end)
|
|
|
|
|
2022-07-02 22:26:54 +00:00
|
|
|
AnsibleInventory.groups.each do |group|
|
|
|
|
short_names = AnsibleInventory.inventory[group]['hosts'].map do |host, vars|
|
|
|
|
{
|
|
|
|
vars['ekumen'] => {
|
|
|
|
host: vars['ansible_host'],
|
|
|
|
hostname: host
|
|
|
|
}
|
|
|
|
}
|
|
|
|
end.inject(&:merge) || {}
|
2022-07-02 19:58:59 +00:00
|
|
|
|
|
|
|
namespace group.to_sym do
|
|
|
|
desc "Run serverspec on #{group}"
|
|
|
|
task all: short_names.keys
|
|
|
|
|
|
|
|
short_names.each_key do |name|
|
|
|
|
desc "Run serverspec on #{group}:#{name}"
|
|
|
|
RSpec::Core::RakeTask.new(name) do |t|
|
2022-07-02 22:26:54 +00:00
|
|
|
ENV['TARGET_HOST'] = short_names[name][:host]
|
|
|
|
ENV['TARGET_HOSTNAME'] = short_names[name][:hostname]
|
2022-07-02 19:58:59 +00:00
|
|
|
|
|
|
|
puts "Running serverspec on #{group}:#{name}"
|
2022-07-02 22:26:54 +00:00
|
|
|
t.pattern = "spec/{base,#{group},#{name}}/*_spec.rb"
|
2022-07-02 19:58:59 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|