Installation of Server spec | Iserver Admin
24/7 Customer Support
20Jun 2017

0

3309

0

Installation of Server spec

Let us Read for you.
Subscribe


With Server spec, you can write R Spec tests for checking your servers are configured correctly. Server spec tests your servers’ actual state by executing command locally, via SSH, via Win Rm, via Docker API and so on. There is no need to install any agent software and can use any configuration management tools, Puppet, Ansible, Cf-engine, Itamae and so on. But the true aim of Server spec is to help refactoring infrastructure code.
Installation
Add this line to your application’s Gemfile:
gem ‘serverspec’
And then execute:
$ bundle
Or install it yourself as:
$ gem install serverspec
Getting Started
$ serverspec-init
Select OS type:
1) UN*X
2) Windows
Step : 1
Select a backend type:
1) SSH
2) Exec (local)
Select number: 1
Vagrant instance y/n: n
Input target host name: www.abc.jp
spec/
spec/www.abc.jp/
spec/www.abc.jp/sample_spec.rb
spec/spec_helper.rb
Rakefile
.rspec
spec/www.abc.jp/sample_spec.rb is a sample spec file and its content is like this.
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
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 like to change the user, please edit the below line in spec/spec_helper.rb.
options[:user] ||= Etc.getlogin
Run tests.

$ rake spec
/usr/bin/ruby -S rspec spec/www.example.jp/sample_spec.rb
Package “httpd”
should be installed
Service “httpd”
⦁ should be enabled
⦁ should be running
Port “80”
should be listening

Finished in 0.21091 seconds (files took 6.37 seconds to load)

Comments (0)