serverspec(1)
serverspec is a Ruby-based framework for testing and validating server infrastructure configuration and state.
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
| Flag | What it does |
|---|---|
init | initialize a new serverspec project with directory structure and example specs |
-h, --hosts HOSTS | specify target hosts for the test run (can be a hostname, IP, or group) |
-p, --properties PROPERTIES | set host properties from command line or external file |
--format FORMAT | specify output format (documentation, json, progress, tap) |
-r, --require PATH | require a file before running tests |
--vagrant | run tests against Vagrant-managed VMs using Vagrant backend |
--docker CONTAINER_ID | run tests against a Docker container |
--sudo | use sudo to run commands on target servers |
Examples
initialize a new serverspec project with interactive prompts for backend type and OS
serverspec-initrun a single spec file against localhost using RSpec
rspec spec/localhost/sample_spec.rbrun all specs in the spec directory against a remote host web01.example.com
rspec spec/ -h web01.example.comrun tests and output results in JSON format for parsing or CI integration
rspec spec/ --format json > results.jsonrun serverspec tests against a running Docker container
rspec spec/ --docker abc123def456run tests against Vagrant boxes defined in Vagrantfile
rspec spec/ --vagrant