Posts

Showing posts with the label serverspec

Server Testing Tools: Serverspec, InSpec, Testinfra, Goss

In this post, I am going to describe differences among server-testing frameworks that I have briefly tried so far: Comparison Serverspec InSpec Testinfra Goss my blog post link link link link language Ruby / RSpec Ruby / RSpec Python / pytest Go / yaml package gem gem pip none remote exec yes yes yes no license MIT Chef Apache 2.0 Apache 2.0 github repo link link link link - created_at 2013 2015 2015 2015 - stars 2.4k 2.3k 1.9k 4.3k Thought Personally, I liked Goss the most as you can write it in yaml. The biggest drawback is that you have to run it on the server itself, and this makes it harder to introduce the tool on the existing production environment. Next, InSpec was easy to start with. I was going to use it at work until I noticed the license issue. Thus, I have basically two options. Serverspec seems great, but since my team members tends to prefer Python to other languages, we might start using Testinfra first.

Testinfra: Quick Start - Run Sample Test to EC2 server

In this post, I am going to try Testinfra . what is Testinfra? Testinfra is a server-testing framework in Python. https://testinfra.readthedocs.io/en/latest/ Similar technologies include: Serverspec, InSpec, and Goss. test server I have create a test server on EC2 as follows: ssh -i test ec2-user@100.26.216.164 https://web-quickstart.blogspot.com/2021/04/terraform-ec2-instance-with-ssh-setup.html install % python --version Python 3.8.5 % pip --version pip 20.2.4 % pip install pytest-testinfra % pip list | grep infra        pytest-testinfra                   6.3.0 run locally (test Mac) % cat root.py def test_passwd_file(host):     passwd = host.file("/etc/passwd")     assert passwd.contains("root")     assert passwd.user == "root" % py.test root.py run remotely (test EC2) Prepare ssh config like below: % cat config  Host testserver   HostName 100.26.216.164   Port 22  ...

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 t...

Serverspec: Quick Start - Run Sample Test to EC2 server

In this post, I am going to install Serverspec and run a sample test on a EC2 instance. what is Serverspec? Serverspec is a server-testing framework in Ruby. A similar technology may include Goss (https://web-quickstart.blogspot.com/2021/04/goss-quick-start-on-awsec2.html ). install % gem install serverspec % gem list serverspec serverspec (2.41.5) If you get " FilePermissionError " see https://web-quickstart.blogspot.com/2021/04/troubleshoot-gem-install.html test server I have created an EC2 instance as: ssh -i test ec2-user@34.203.28.211 reference: https://web-quickstart.blogspot.com/2021/04/terraform-ec2-instance-with-ssh-setup.html init project % serverspec-init Select OS type:   1) UN*X   2) Windows Select number: 1 Select a backend type:   1) SSH   2) Exec (local) Select number: 1 Vagrant instance y/n: n Input target host name: 34.203.28.211  + spec/  + spec/34.203.28.211/  + spec/34.203.28.211/sample_spec.rb  + spec/spec_helper.rb  + R...

Goss: Quick Start on AWS/EC2

In this post, I am going to try Goss on a EC2 instance. what is goss? Goss is ServerSpec in Go. You can define tests as yaml. https://github.com/aelsabbahy/goss test server You can create a test ec2 instance: https://web-quickstart.blogspot.com/2021/04/terraform-ec2-instance-with-ssh-setup.html install $ curl -fsSL https://goss.rocks/install | sh touch: cannot touch '/usr/local/bin/goss': Permission denied ERROR: Cannot write to /usr/local/bin set GOSS_DST elsewhere or use sudo I just added sudo to solve it. Note: use manual installation for production servers as mentioned in the github page. $ curl -fsSL https://goss.rocks/install | sudo sh $ goss --version goss version v0.3.16 generate tests You can use autoadd command to have the initial cases. $ goss autoadd sshd goss.yaml is created as follows: service:   sshd:     enabled: true     running: true user:   sshd:     exists: true     uid: 74     gid: 74     groups:...