Getting started with Serverspec
Saturday, Aug 16, 2014 11:16 · 233 words · 2 minutes read
Serverspec Series
What is Serverspec?
Rspec tests for verifying the configuration of a given machine. It is used together with configuration management tools like Salt, Ansible, Puppet, Chef, etc. as a integration testing framework.
It is a Ruby-based framework, which uses internally Shell(Linux environments), Powershell(Windows environment) scripts for checking the target machines if the configuration management tool has configured them correctly.
Installation
The easiest way to install is to use the serverspec gem:
gem install serverspec
Usage
I will concentrate on testing Windows machines using the Serverspec framework, but the approach is the same for Linux ones.
To get started with Serverspec, the serverspec-init tool can be used, it creates the needed setup for a testing suite:
serverspec-init
Select OS type:
1) UN*X
2) Windows
Select number: 2
Select a backend type:
1) SSH
2) Exec (local)
Select number: 2
Note: The setup is done for windows local environment.
The command will create the following setup on the local machine:
▾ spec/
▾ localhost/
httpd_spec.rb
spec_helper.rb
Rakefile
The httpd_spec.rb contains example Rspec tests.
Executing the rake spec command(rake gem is needed) will run the Rspec tests.
rake spec
Resource Types
Serverspec has many different resource types implemented, which allow users to describe the machine setup in their Rspec tests.
Helpful information about these resource types can be found here.