An introduction to

What is

is

  • A unit test framework for servers written in Ruby
  • Based on the rspec testing framework for Ruby
  • Agentless & OS independent

is NOT

  • A configration management tool, although...
  • An IDS, although...
  • An monitoring system, although...

How does

work?

Installation



# gem install serverspec

will install Serverspec and all dependencies

Writing a test



require 'serverspec'

set :backend, :exec

context 'My first serverspec test' do
  describe file('/etc/passwd') do
    it { should exist }
    it { should be_file }
    it { should be_owned_by 'root' }
  end 
end 

Running the test



$ rspec my_first_test_spec.rb 
...

Finished in 0.64969 seconds \
 (files took 4.04 seconds to load)
3 examples, 0 failures

...verbose



$ rspec -f d my_first_test_spec.rb 

My first serverspec test
  File "/etc/passwd"
    should exist
    should be file
    should be owned by "root"

Finished in 0.76407 seconds \
 (files took 3.53 seconds to load)
3 examples, 0 failures

...and for management

interactive html reports

What else can be checked?

  • bond
  • bridge
  • cgroup
  • command
  • cron
  • default_gateway
  • docker_container
  • docker_image
  • file
  • group
  • host
  • iis_app_pool
  • iis_website
  • interface
  • ip6tables
  • ipfilter
  • ipnat
  • iptables
  • kernel_module
  • linux_audit_system
  • linux_kernel_parameter
  • lxc
  • mail_alias
  • mysql_config
  • package
  • php_config
  • port
  • ppa
  • process
  • routing_table
  • selinux
  • selinux_module
  • service
  • user
  • x509_certificate
  • x509_private_key
  • windows_feature
  • windows_registry_key
  • yumrepo
  • zfs

Architecture

Specinfra

Rspec

Syntax

Matchers

it { should be_<keyword> [parameter] }
it { should have_<keyword> [parameter] }

Yields

Boolean

Syntax

its Matchers

its(:content) { should match /regexp/ }

Yields

String

The work horse Specinfra

  • Determines the OS and environment
  • Sets the backend e.g. :exec or :ssh among others
  • Executes commands via the backend
  • Gathers host information via host_inventory

Specinfra Supported Operating Systems

  • Linux
  • Docker
  • LXC
  • Amazon AWS
  • FreeBSD
  • OpenBSD
  • Solaris
  • AIX
  • Windows

Specinfra Backends

  • cmd
  • dockerfile
  • docker
  • exec
  • lxc
  • powershell
  • shell_script
  • ssh
  • telnet
  • winrm

Combined with

  • sudo

serverspec.org

serverspec.org