Serverspec

Serverspec on Centos

Serverspec allow you to develop RSpec aka understandable, repeatable infrastructure tests (

Installing
# yum install rubygems
# gem install bundler
# gem install rake
# gem install serverspec

# serverspec-init
Select OS type:

  1) UN*X
  2) Windows

Select number: 1

Select a backend type:

  1) SSH
  2) Exec (local)

Select number: 2

 + spec/
 + spec/localhost/
 + spec/localhost/sample_spec.rb
 + spec/spec_helper.rb
 + Rakefile
 + .rspec

Editing - the spec file (spec/localhost/sample_spec.rb)

require 'spec_helper'

describe package('httpd'), :if => os[:family] == 'redhat' do
  it { should be_installed }
end

describe package('apache2'), :if => os[:family] == 'ubuntu' do
  it { should be_installed }
end

describe service('httpd'), :if => os[:family] == 'redhat' do
  it { should be_enabled }
  it { should be_running }
end

describe service('apache2'), :if => os[:family] == 'ubuntu' do
  it { should be_enabled }
  it { should be_running }
end

describe service('org.apache.httpd'), :if => os[:family] == 'darwin' do
  it { should be_enabled }
  it { should be_running }
end

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

Running

# rake spec
/usr/bin/ruby -I/usr/local/share/gems/gems/rspec-core-3.7.0/lib:/usr/local/share/gems/gems/rspec-support-3.7.0/lib /usr/local/share/gems/gems/rspec-core-3.7.0/exe/rspec --pattern spec/localhost/\*_spec.rb

Package "httpd"
  should be installed

Service "httpd"
  should be enabled
  should be running

Port "80"
  should be listening

Finished in 0.05114 seconds (files took 0.27387 seconds to load)
4 examples, 0 failures
#

All tests pass, this assumes that httpd is installed, enabled, and running on port 80.

Author | Miles Davenport

Career programmer, who designs, assembles, fixes, and supports customers, software and systems.