Introduction
Goss is a YAML based serverspec alternative tool for validating a server’s configuration. It’s written on Go language. It’s quite interesting and promising young project I came across via reddit/devops channel.
Let me show how one can distribute goss scenarios using sparrow tasks.
Before diving into technical stuff let me explain why this could be useful:
- you want organize multiple goss scenarios by logical groups and manage them via unified interface
- you want to share some goss yamls across your team, to make it possible quickly run your goss tests against many applications
Ok, let’s go.
Installing sparrow goss plugin
This part is really easy.
$ sparrow index update # we want fresh index from SparrowHub $ sparrow plg install goss
You’ll find detailed information on goss sparrow plugin at https://sparrowhub.org/info/goss
Set up sparrow project and tasks
Ok, now let’s create sparrow project and tasks. These are just simple abstractions to split many goss tests on various logical groups.
$ sparrow project audit # we will keep all goss scenarios here $ sparrow task add audit nginx goss # nginx test suite $ sparrow task add audit mysql goss # mysql test suite
Running sparrow task list command we see our new project and tasks:
$ sparrow task list [sparrow task list] [audit] audit/mysql audit/nginx
Set up goss tests
Now let’s populate our goss tests, we should read goss spec first, but it’s really easy.
One for nginx:
$ sparrow task ini audit/nginx
action validate
goss << HERE
port:
tcp:80:
listening: true
ip:
- 0.0.0.0
service:
nginx:
enabled: true
running: true
process:
nginx:
running: true
HERE
And one for mysql:
$ sparrow task ini audit/mysql
action validate
goss << HERE
port:
tcp:3306:
listening: true
ip:
- 127.0.0.1
service:
mysql:
enabled: true
running: true
process:
mysqld:
running: true
HERE
Run goss tests
Now we can run goss tests separately for nginx and mysql.
One for nginx:
$ sparrow task run audit/nginx [t] nginx @ goss wrapper [t] nginx modules/generate-goss-yaml/ params: cache_dir:/home/vagrant/.outthentic/tmp/9595/story-1 at 2017-03-07 16:18:13 generated goss yaml at /home/vagrant/.outthentic/tmp/9595/story-1/goss.yaml ok scenario succeeded [t] nginx modules/validate/ at 2017-03-07 16:18:13 1..5 ok 1 - Process: nginx: running: matches expectation: [true] ok 2 - Port: tcp:80: listening: matches expectation: [true] ok 3 - Port: tcp:80: ip: matches expectation: [["0.0.0.0"]] ok 4 - Service: nginx: enabled: matches expectation: [true] ok 5 - Service: nginx: running: matches expectation: [true] ok scenario succeeded STATUS SUCCEED
And one for mysql:
$ sparrow task run audit/mysql [t] mysql @ goss wrapper [t] mysql modules/generate-goss-yaml/ params: cache_dir:/home/vagrant/.outthentic/tmp/9901/story-1 at 2017-03-08 08:19:14 generated goss yaml at /home/vagrant/.outthentic/tmp/9901/story-1/goss.yaml ok scenario succeeded [t] mysql modules/validate/ at 2017-03-08 08:19:14 1..5 ok 1 - Process: mysqld: running: matches expectation: [true] ok 2 - Port: tcp:3306: listening: matches expectation: [true] ok 3 - Port: tcp:3306: ip: matches expectation: [["127.0.0.1"]] ok 4 - Service: mysql: enabled: matches expectation: [true] ok 5 - Service: mysql: running: matches expectation: [true] ok scenario succeeded STATUS SUCCEED
Sharing goss tests
An interesting use case is you may share you goss tests. Sparrow make it possible save your tasks at SparrowHub – central sparrow repository so that to share tasks with others.
Say you want someone else runs your goss scenarios on remote server. Provided that one install sparrow client there, it is really easy.
Upload remote task
$ sparrow remote task upload audit/nginx "goss audit for nginx" $ sparrow remote task share audit/nginx
$ sparrow remote task upload audit/mysql "goss audit for mysql" $ sparrow remote task share audit/mysql
Install and run remote task
Having logged into other server just have this:
$ sparrow remote task run melezhik@audit/nginx $ sparrow remote task run melezhik@audit/mysql
More on remote task could be found at sparrow documentation – https://github.com/melezhik/sparrow#remote-tasks
Running goss scenarios with sparrowdo
Alternatively you may want to use Perl6 interface to sparrow and run goss scenarios using sparrowdo:
$ cat sparrowfiletask-run 'run goss for mysql', 'goss', %(
action => 'validate' , goss => q:to/HERE/ ); port: tcp:3306: listening: true ip: - 127.0.0.1 service: mysql: enabled: true running: true process: mysqld: running: true HERE $ sparrowdo --host=192.168.0.1
—
Regards and have fun with automation.
Leave a Reply