Posts

Showing posts from September, 2016

serverspec to verify our IIS Configuration

An example serverspec to run some basis tests of IIS website configuration e.g. exists, enabled, running, the app pool under which it is running, the port and protocol binding and the folder/path where the web application code is.

describe 'IIS Website resource type' do
  describe iis_website('Business Application Root') do
    it { should exist }
    it { should be_enabled }
    it { should be_running }
    it { should be_in_app_pool('Business Application Pool') }
    it{ should have_site_bindings(443).with_protocol('https') }
    it { have_physial_path('d:\\businessapplications\\www') }
  end
end

Check FTP Publishing with serverspec - Infrastructure Testing

Serverspec tests the actual state of your server infrastructure by executing command locally (CMD), via SSH, via WinRM, via Docker API and so on.

There is no agent technology required on your servers and can use any configuration management tools, Puppet, Ansible, CFEngine, Itamae, Saltstack and so on.

Create a file CheckFTP.rb with the following contents

require 'spec_helper'
describe 'FTP Publishing' do
  describe service('FTP Publishing') do
    it { should be_installed }
    it { should be_enabled }
    it { should be_running }
    it { should have_start_mode('Automatic') }
  end
  describe port(21) do
    it { should be_listening.with('tcp') }
  end
end

Run the serverspec file
ruby -S rspec CheckFTP.rb.rb

Expected Output
FTP Publishing
  Service "FTP Publishing"
    should be installed
    should be enabled
    should be running
    should have start mode "Automatic"
  Port "21"
    should be listening with tcp

Fi…

TestInfra - Testing Your Infrastructure

Write unit tests in Python with Testinfra to test the state of your servers configured by managements tools like Salt, Ansible, Puppet, Chef.

Today TestInfra does not support Terraform but maybe this is something to build as a custom module in our environment

Below is a very simple TestInfra script to verify if apache is running

vi apachecheck.py

def test_apache2_is_installed(Package):
    apache2 = Package("apache2")
    assert apache2.is_installed
    assert apache2.version.startswith("2.2")

Then run with

testinfra  -v apachecheck.py
==================================================== test session starts
platform linux2 -- Python 2.7.3, pytest-3.0.1, py-1.4.31, pluggy-0.3.1 -- /usr/bin/python
cachedir: .cache
rootdir: /root, inifile:
plugins: testinfra-1.4.2
collected 1 items

apachecheck.py::test_apache2_is_installed[local] PASSED

================================================== 1 passed in 0.53 seconds

Now edit and change the version number to invalid i.e. 3.…