Git Product home page Git Product logo

serverspec's Introduction

Serverspec Gem Version BuildStatus Code Climate

RSpec tests for your servers configured by Puppet, Chef or anything else

You can see the details of serverspec on serverspec.org.


Installation

Add this line to your application's Gemfile:

gem 'serverspec'

And then execute:

$ bundle

Or install it yourself as:

$ gem install serverspec

Usage

$ serverspec-init
Select a backend type:

  1) SSH
  2) Exec (local)

Select number: 1

Input target host name: www.example.jp

 + spec/
 + spec/www.example.jp/
 + spec/www.example.jp/httpd_spec.rb
 + spec/spec_helper.rb
 + Rakefile

spec/www.example.jp/httpd_spec.rb is a sample spec file and its content is like this.

require 'spec_helper'

describe package('httpd') do
  it { should be_installed }
end

describe service('httpd') do
  it { should be_enabled }
  it { should be_running }
end

describe port(80) do
  it { should be_listening }
end

describe file('/etc/httpd/conf/httpd.conf') do
  it { should be_file }
  it { should contain "ServerName www.example.jp" }
end

You can write spec for testing servers like this.

Serverspec with SSH backend logs in to target servers as a user configured in ~/.ssh/config or a current user.If you'd lile to change the user, please edit the below line in spec/spec_helper.rb.

      user    = options[:user] || Etc.getlogin

Run tests.

$ rake spec
/usr/bin/ruby -S rspec spec/www.example.jp/httpd_spec.rb
......

Finished in 0.99715 seconds
6 examples, 0 failures

Multi OS support

Serverspec is supporting Darwin based OS, Red Hat based OS, Debian based OS, Gentoo and Solaris.

Serverspec can detect target host's OS automatically.

If you'd like to set target host's OS explicitly, you should include Serverspec::Helper::OSName in spec/spec_helper.rb like this.

require 'serverspec'
require 'pathname'
require 'net/ssh'

include Serverspec::Helper::Ssh
include Serverspec::Helper::Debian

RSpec.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
  end
end

You can select Serverspec::Helper::RedHat, Serverspec::Helper::Debian, Serverspec::Helper::Gentoo , Serverspec::Helper::Solaris or Serverspec::Helper::Darwin.

Vagrant support

Serverspec now has Vagrant support, and can be automatically configured from a Vagrantfile

$ serverspec-init
Select a backend type:

  1) SSH
  2) Exec (local)

Select number:1

Vagrant instance y/n: y
Auto-configure Vagrant from Vagrantfile? y/n: y
0) web
1) db
1
 + spec/db/
 + spec/db/httpd_spec.rb
 + spec/spec_helper.rb
 + Rakefile

See details on serverspec.org


Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

serverspec's People

Contributors

mizzy avatar kitak avatar ftnk avatar smontanari avatar podenski avatar koemu avatar raphink avatar ryotarai avatar petems avatar matsuo avatar sawanoboly avatar studio3104 avatar kentaro avatar hfm avatar netmarkjp avatar matsuu avatar linyows avatar flozano avatar takatoshi-maeda avatar tomohiro avatar hayato1980 avatar a3no avatar kotakanbe avatar aibou avatar tenforward avatar darron avatar wubel avatar cs-travis avatar kenjiskywalker avatar catatsuy avatar

Watchers

James Cloos avatar Rahul Khengare avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.