InSpec: Quick Start - Run Sample Test to EC2 server

In this post, I am going to install InSpec and try it.


what is InSpec?

InSpec is a server-testing framework developed by Chef. It is similar to Serverspec .

To see the difference between Serverspec and InSpec, as well as how to migrate from Serverspec, you can check: https://docs.chef.io/inspec/migration/

The license agreement is required for "Personal, Non-Commercial, Experimental" https://www.chef.io/end-user-license-agreement


test server

I have create a test server on EC2 as follows:

ssh -i test ec2-user@34.207.64.183

https://web-quickstart.blogspot.com/2021/04/terraform-ec2-instance-with-ssh-setup.html


install

% gem install inspec

% gem install inspec-bin

% inspec -v

4.33.1


usage from help command

% inspec exec -h

Options:

  t, [--target=TARGET]            # Simple targeting option using URIs, e.g. ssh://user:pass@host:port

  i, [--key-files=one two three]  # Login key or certificate file for a remote scan.


test (fail)

Prepare a test file "httpd.rb" as follows:

% cat httpd.rb 

describe package('httpd') do

  it { should be_installed }

end

Run the test specifying the private key. It should result in failure:

% inspec exec httpd.rb -t ssh://ec2-user@34.207.64.183 -i test


fix and test again (succeed)

Install apache server on the remote server.

$ sudo yum install httpd

Running the test will result in success this time.

% inspec exec httpd.rb -t ssh://ec2-user@34.207.64.183 -i test


Comments

Popular posts from this blog

Minikube Installation for M1 Mac

Selenide: Quick Start

Ansistrano (Ansible + Capistrano): Quick Start