LoginSignup
1
0

More than 5 years have passed since last update.

gossを使ってみよう

Posted at

goss って何?

簡単に言うと goss は serverspec みたいな感じのサーバーなどの設定をテスト/検証するツールです。YAML でテストすることを書いて実行するだけで、簡単にサーバーのテスト/検証ができます。また現在のサーバーの状態を元にテスト項目を生成することができます。

以下の動画を見て頂ければどんなものかが簡単にわかると思います。

Goss in 45 seconds

インストールしてみよう

https://github.com/aelsabbahy/goss/releases からバイナリをダウンロードしてきてパスの通っている場所に置くだけです。(現在、Linux 向けのバイナリのみ)
もしくは以下のように実行して設置します。(64bit 環境の場合)

$ GOSS_VER=v0.3.4 && sudo -E curl -L https://github.com/aelsabbahy/goss/releases/download/$GOSS_VER/goss-linux-amd64 -o /usr/local/bin/goss
$ sudo chmod +rx /usr/local/bin/goss

ちなみに dgoss っていうファイルは docker 環境下で goss を簡単に手早く使うためのラッパーだそうです。別の機会に説明します。

使ってみよう

テストするために YAML ファイルをバリバリと書くのもいいんですが、goss には自動でテスト項目を生成してくれるコマンドがあるので、まずはそれを使って YAML を生成してみます。

$ goss -g sshd_goss.yaml autoadd sshd

と実行すると以下のような内容が出力されます。

Adding Process to 'sshd_goss.yaml':

sshd:
  running: true


Adding Service to 'sshd_goss.yaml':

sshd:
  enabled: true
  running: true


Adding User to 'sshd_goss.yaml':

sshd:
  exists: true
  uid: 122
  gid: 65534
  groups:
  - nogroup
  home: /var/run/sshd
  shell: /usr/sbin/nologin

なお、同じような内容の YAML が -g オプションで指定したファイルに出力されます。

$ cat sshd_goss.yaml 
service:
  sshd:
    enabled: true
    running: true
user:
  sshd:
    exists: true
    uid: 122
    gid: 65534
    groups:
    - nogroup
    home: /var/run/sshd
    shell: /usr/sbin/nologin
process:
  sshd:
    running: true

この出力された YAML ファイルを使ってテストを実施するには以下のように実行します。

$ goss -g sshd_goss.yaml validate
.........

Total Duration: 0.017s
Count: 9, Failed: 0, Skipped: 0

テストにかかった時間とテスト結果が出力されます。


他のオプションについては追い追い追記していきます。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0