What is Serverspec
Serverspec can test and check your servers on Rspec test cases to ensure certain configurations are present and any packages are existing in a server a remote host.
It test server’s state by executing ruby commands locally via API’s like SSH, docker and so on. Serverspec can work with any configuration management tool like Puppet,Ansible or CHEF.
Installation
Install gem on your host
~$ sudo apt-get install gem
Then perform a gem install to setup serverspec
~$ sudo gem install serverspec
Initiating Serverspec on a Host
~$ 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
Then there will be a file structure setup like above. the sample_spec.rb file contains the Rspec tests to run.
The sample Rspec checks for apache2/httpd package in the host according to it’s os family and whether the service apache2/httpd is up and running.
You can go to the directory whre serverspec-init was created. and rn the test by invoking ruby rake.
~$ rake spec
The output will be like following after runiing the Rspec tests.
In here spec is the localhost rspec test structure created. It’ll call all files with the name including _spec.rb. Of cause you can change it as you wish in the Rakefile.