Subscribed unsubscribe Subscribe Subscribe

Kentaro Kuribayashi's blog

Software Engineering, Management, Books, and Daily Journal.

Syllabus 0.0.2 and Specinfra

Syllabus 0.0.2 has been released. From this version, it depends on specinfra. specinfra now provides several common libraries that is useful when we write our own server testing tools (like serverspec) or configuration management tools (like Syllabus or configspec).

People have their own preference to how much abstract their tool should be; to configure servers, some may say shell scripts are enough, others may say high abstraction layer is needed like Chef/Puppet. specinfra just provides common libraries so that we can wrap it and make suitable interface for us on it.

I'll show you how specinfra works (this is super great). Below is the core file of Syllabus. It consists of just 17 lines of codes. In the code below, specinfra does the things such as:

  1. Detects automatically what the OS on which the code is running is
  2. Returns appropriate backend object for the type passed (backend is a specinfra's term that is responsible for how the command should be dispatched)
  3. Builds command statements like yum install -y httpd
  4. Executes the commands above via the backend object
require 'specinfra'

class Syllabus::Core
  extend SpecInfra::Helper::Backend
  extend SpecInfra::Helper::DetectOS

  def self.run(args)
    backend = backend_for(args[:type])
    config  = Syllabus::Config.new_from_file(file: args[:file], backend: backend)
    logger  = Syllabus::Logger.new(level: args[:level])

    config.commands.each do |command|
      result = backend.run_command(command)
      logger.log(command, result)
    end
  end
end

The example above is for a configuration management tool. Although specinfra has not implemented enough commands for CMT yet, it has enough commands for server testing tool, which allows you to create another testing tool that can work at least as comprehensive as serverspec.

Let's create your own DevOps tools with specinfra. Enjoy!