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:
    - sshd
    home: /var/empty/sshd
    shell: /sbin/nologin
group:
  sshd:
    exists: true
    gid: 74
process:
  sshd:
    running: true
package:
  httpd:
    title: apache is installed
    installed: true
[ec2-user@ip-172-31-92-245 ~]$ cat goss.yaml | pbcopy
-bash: pbcopy: command not found
[ec2-user@ip-172-31-92-245 ~]$ cat goss.yaml
service:
  sshd:
    enabled: true
    running: true
user:
  sshd:
    exists: true
    uid: 74
    gid: 74
    groups:
    - sshd
    home: /var/empty/sshd
    shell: /sbin/nologin
group:
  sshd:
    exists: true
    gid: 74
process:
  sshd:
    running: true

validate

$ goss validate

...........

Total Duration: 0.023s

Count: 11, Failed: 0, Skipped: 0


add apache case

Update goss.yaml to append a package check as follows:

process:
  sshd:
    running: true

package:
  httpd:
    title: apache is installed
    installed: true

The validation fails:

$ goss validate

...

Total Duration: 0.050s

Count: 12, Failed: 1, Skipped: 0

It succeeds after you install the software.

$ sudo yum install httpd

$ goss validate

............

Total Duration: 0.051s

Count: 12, Failed: 0, Skipped: 0


Comments

Popular posts from this blog

Minikube Installation for M1 Mac

Selenide: Quick Start

Ansistrano (Ansible + Capistrano): Quick Start