hands-on lab

Infrastructure Testing with Serverspec

Up to 45m
Get guided in a real environmentPractice with a step-by-step scenario in a real, provisioned environment.
Learn and validateUse validations to check your solutions every step of the way.
See resultsTrack your knowledge and monitor your progress.


Lab Overview

An important principle in DevOps is to test your infrastructure. The tests should run as part of your continuous delivery pipeline giving you agility and confidence in your infrastructure changes. Serverspec is one example of an infrastructure testing framework. Serverspec can be used to test local and remote target machines by connecting over SSH or WinRM.

This Lab illustrates how to perform Infrastructure Testing with Serverspec. You will write Serverspec tests to specify the expected behavior of machines running in the reverse-proxy, load-balancing tier and the application tier of a sample application. The tests illustrate how to describe the expected behavior of servers and Docker containers. You will run the tests using Serverspec at the command-line and in a Docker container.

Lab Objectives

Upon completion of this Lab, you will be able to:

  • Understand where automated infrastructure testing fits into DevOps
  • Initialize Serverspec infrastructure test suites
  • Write Serverspec tests for a variety of Serverspec resources including packages, services, ports, and Docker infrastructure
  • Run Serverspec from the command line and in a Docker container

Lab Prerequisites

You should be familiar with:

  • A programming language. Ruby familiarity is most beneficial, but not required.
  • Basic Docker concepts, such as images and containers
  • Basic Linux concepts, such as the command line, processes, packages, and services

Lab Environment

Before completing the Lab instructions, the environment will look as follows:

After completing the Lab instructions, the environment should look similar to:



June 24th, 2024 - Minor typo correction to reflect UI


June 12th, 2024 - Resolved Serverspec test issue

March 27th, 2023 - Resolved an issue that caused the lab to fail to set up on rare occasions

December 5th, 2022 - Added checks to track lab progress

May 3rd, 2019 - Updated packages that caused Docker to fail to install on the Application instance

January 10th, 2019 - Added a validation Lab Step to check the work you perform in the Lab

About the author

Logan Rakai, opens in a new tab
Lead Content Developer - Labs
Learning paths

Logan has been involved in software development and research since 2007 and has been in the cloud since 2012. He is an AWS Certified DevOps Engineer - Professional, AWS Certified Solutions Architect - Professional, Microsoft Certified Azure Solutions Architect Expert, MCSE: Cloud Platform and Infrastructure, Google Cloud Certified Associate Cloud Engineer, Certified Kubernetes Security Specialist (CKS), Certified Kubernetes Administrator (CKA), Certified Kubernetes Application Developer (CKAD), and Certified OpenStack Administrator (COA). He earned his Ph.D. studying design automation and enjoys all things tech.

LinkedIn, Twitter, GitHub

Covered topics

Lab steps

Logging In to the Amazon Web Services Console
Opening the AWS Cloud9 IDE
Running a Local Serverspec Test Suite
Testing Remote Infrastructure with Serverspec
Testing Docker Infrastructure With Serverspec
Running Serverspec in a Docker Container