serverspec主要是为Puppet,Chef和其他配置管理工具提供测试服务器配置的功能,也提供RSpec测试。
示例代码:
require 'serverspec'require 'pathname'require 'net/ssh'include Serverspec::Helper::Sshinclude Serverspec::Helper::DebianRSpec.configure do |c| # Add SSH before hook in case you use the SSH backend # (not required for the Exec backend) c.before do host = File.basename(Pathname.new(example.metadata[:location]).dirname) if c.host != host c.ssh.close if c.ssh c.host = host options = Net::SSH::Config.for(c.host) user = options[:user] || Etc.getlogin c.ssh = Net::SSH.start(c.host, user, options) end endend
评论