Sha256: cfd472e1a92626afbc228135f4c52f6945be5d5bca0817570c3d00311e3bb25a

Contents?: true

Size: 1.3 KB

Versions: 7

Compression:

Stored size: 1.3 KB

Contents

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 do |property|
    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}"
        if host.instance_of?(Hash)
          ENV['TARGET_HOST'] = host["uri"]
          ENV['TARGET_PORT'] = host["port"].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
        else
          ENV['TARGET_HOST'] = host
          ENV['TARGET_PRIVATE_KEY'] = '~/.ssh/id_rsa'
          ENV['TARGET_USER'] = property["user"]
        end
        t.pattern = 'roles/{' + property["roles"].join(',') + '}/spec/*_spec.rb'
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
ansible_spec-0.2.4 lib/src/Rakefile
ansible_spec-0.2.3 lib/src/Rakefile
ansible_spec-0.2.2 lib/src/Rakefile
ansible_spec-0.2.1 lib/src/Rakefile
ansible_spec-0.2 lib/src/Rakefile
ansible_spec-0.1.1 lib/src/Rakefile
ansible_spec-0.1 lib/src/Rakefile