LoginSignup
10
12

More than 5 years have passed since last update.

あなたのansibleとserverspecの併用は間違っている!

Last updated at Posted at 2017-09-12

あなたの間違った使い方

そもそも併用する動機が間違っている

「ansibleのコードが正しいか不安だから、serverspecでチェックする」という動機で併用する方がいますが、間違いです。
serverspecのコードが絶対に正しいと言えない限り、チェックすることは不可能です。

ansibleとserverspecで同じ結果をチェックする

ansibleで、

- name: restart hogehoge.service
  systemd:
    name: hogehoge.service
    state: restarted
    daemon_reload: yes
    enabled: yes
  become: yes

と書いておいて、serverspecで、

describe process('hogehoge') do
  it { should be_running }
end

だけ書くのも間違いです。

systemdモジュールはべき等性が保証されているため、serverspecでプロセス起動の有無をチェックすることは無意味です。
TDDの「不安をテストする」という金言を知ったなら、べき等の意味もおさえましょう。

もし、どうしてもserverspecでチェックするのであれば、プロセス起動以外にサービスが参照する設定ファイルの値を確認するべきです。
ただし、それらすべてのチェック項目はansibleで確認できてしまうことを覚えておいて下さい。

10
12
1

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
10
12