$linuxjunkies
>

serverspec(1)

serverspec is a Ruby-based framework for testing and validating server infrastructure configuration and state.

UbuntuDebianFedoraArch

Synopsis

serverspec [COMMAND] [OPTIONS]

Description

Serverspec is an RSpec-based testing framework that allows you to write executable specifications for your infrastructure. It verifies that servers are configured correctly by testing packages, services, ports, files, and system properties without requiring SSH root access.

Tests are written in Ruby using a domain-specific language (DSL) that reads like English. Serverspec uses Specinfra under the hood to interact with servers via SSH, WinRM, or local execution, making it ideal for infrastructure as code validation and server compliance checking.

Common options

FlagWhat it does
initinitialize a new serverspec project with directory structure and example specs
-h, --hosts HOSTSspecify target hosts for the test run (can be a hostname, IP, or group)
-p, --properties PROPERTIESset host properties from command line or external file
--format FORMATspecify output format (documentation, json, progress, tap)
-r, --require PATHrequire a file before running tests
--vagrantrun tests against Vagrant-managed VMs using Vagrant backend
--docker CONTAINER_IDrun tests against a Docker container
--sudouse sudo to run commands on target servers

Examples

initialize a new serverspec project with interactive prompts for backend type and OS

serverspec-init

run a single spec file against localhost using RSpec

rspec spec/localhost/sample_spec.rb

run all specs in the spec directory against a remote host web01.example.com

rspec spec/ -h web01.example.com

run tests and output results in JSON format for parsing or CI integration

rspec spec/ --format json > results.json

run serverspec tests against a running Docker container

rspec spec/ --docker abc123def456

run tests against Vagrant boxes defined in Vagrantfile

rspec spec/ --vagrant

Related commands