These are snippets of auto-generated from ServerSpec. The serverspec-init only auto-generates base functionality with cmd, exec, ssh, and winrm backends with some optional vagrant support for dyanmic inventory on ssh backend.
There are additional backends available from SpecInfra, but these are not supported and only documented in O'Reilly book for Serverspec: The Definitive Guide by Gosuke Miyashita (ISBN978-4-87311-709-6), which is in Japanese only:
require 'serverspec'
set :backend, :cmdrequire 'serverspec'
set :backend, :execrequire 'serverspec'
require 'winrm'
set :backend, :winrm
user = <username>
pass = <password>
endpoint = "http://#{ENV['TARGET_HOST']}:5985/wsman"
winrm = ::WinRM::WinRMWebService.new(endpoint, :ssl, :user => user, :pass => pass, :basic_auth_only => true)
winrm.set_timeout 300 # 5 minutes max timeout for any operation
Specinfra.configuration.winrm = winrmrequire 'serverspec'
require 'net/ssh'
set :backend, :ssh
if ENV['ASK_SUDO_PASSWORD']
begin
require 'highline/import'
rescue LoadError
fail "highline is not available. Try installing it."
end
set :sudo_password, ask("Enter sudo password: ") { |q| q.echo = false }
else
set :sudo_password, ENV['SUDO_PASSWORD']
end
host = ENV['TARGET_HOST']
options = Net::SSH::Config.for(host)
options[:user] ||= Etc.getlogin
set :host, options[:host_name] || host
set :ssh_options, optionsrequire 'serverspec'
require 'net/ssh'
require 'tempfile'
set :backend, :ssh
if ENV['ASK_SUDO_PASSWORD']
begin
require 'highline/import'
rescue LoadError
fail "highline is not available. Try installing it."
end
set :sudo_password, ask("Enter sudo password: ") { |q| q.echo = false }
else
set :sudo_password, ENV['SUDO_PASSWORD']
end
host = ENV['TARGET_HOST']
`vagrant up #{host}`
config = Tempfile.new('', Dir.tmpdir)
config.write(`vagrant ssh-config #{host}`)
config.close
options = Net::SSH::Config.for(host, [config.path])
options[:user] ||= Etc.getlogin
set :host, options[:host_name] || host
set :ssh_options, optionsset :disable_sudo, true
set :env, :LANG => 'C', :LC_MESSAGES => 'C'
set :path, '/sbin:/usr/local/sbin:$PATH'No automation at the moment for Docker.
- https://github.com/mizzy/specinfra/blob/master/lib/specinfra/backend/docker.rb
- https://github.com/mizzy/specinfra/blob/master/lib/specinfra/backend/dockerfile.rb
- https://github.com/mizzy/specinfra/blob/master/lib/specinfra/backend/cmd.rb
- https://github.com/mizzy/specinfra/blob/master/lib/specinfra/backend/exec.rb
- https://github.com/mizzy/specinfra/blob/master/lib/specinfra/backend/ssh.rb
- https://github.com/mizzy/specinfra/blob/master/lib/specinfra/backend/ssh.rb
Called From:
require 'rake'
require 'rspec/core/rake_task'
task :spec => 'spec:all'
task :default => :spec
namespace :spec do
targets = []
Dir.glob('./spec/*').each do |dir|
next unless File.directory?(dir)
target = File.basename(dir)
target = "_#{target}" if target == "default"
targets << target
end
task :all => targets
task :default => :all
targets.each do |target|
original_target = target == "_default" ? target[1..-1] : target
desc "Run serverspec tests to #{original_target}"
RSpec::Core::RakeTask.new(target.to_sym) do |t|
ENV['TARGET_HOST'] = original_target
t.pattern = "spec/#{original_target}/*_spec.rb"
end
end
end