serverspecを導入したものの放置気味な人へ
TRANSCRIPT
![Page 1: Serverspecを導入したものの放置気味な人へ](https://reader033.vdocuments.pub/reader033/viewer/2022050613/587e98db1a28ab672b8b7297/html5/thumbnails/1.jpg)
Serverspecを導入したものの放置気味な人へ
Ansible Meetup in Tokyo 2015.09
@ks888sk
![Page 2: Serverspecを導入したものの放置気味な人へ](https://reader033.vdocuments.pub/reader033/viewer/2022050613/587e98db1a28ab672b8b7297/html5/thumbnails/2.jpg)
自己紹介
● @ks888sk (やがみ)
○ メーカー系企業のインフラエンジニア
○ Ansibleはここ一年くらい実サービスで使ってみています
○ Ansible向けのデバッガとか作ってます
![Page 3: Serverspecを導入したものの放置気味な人へ](https://reader033.vdocuments.pub/reader033/viewer/2022050613/587e98db1a28ab672b8b7297/html5/thumbnails/3.jpg)
Serverspec
● サーバの設定をテストするツール○ らくらく導入
■ gemで一発■ 初期化スクリプトあり〼
○ テストが簡単に書ける
describe package('httpd') it { should be_installed }end
![Page 4: Serverspecを導入したものの放置気味な人へ](https://reader033.vdocuments.pub/reader033/viewer/2022050613/587e98db1a28ab672b8b7297/html5/thumbnails/4.jpg)
Serverspecあるある
1. Serverspecを導入してみる
○ 導入後しばらくは、ちゃんとテストを書く
2. 数々の理由から、テストを書かなくなる
○ 忙しくて。。忘れてて。。。
3. 設定ミスが問題を起こす
○ テスト書いていれば...!
![Page 5: Serverspecを導入したものの放置気味な人へ](https://reader033.vdocuments.pub/reader033/viewer/2022050613/587e98db1a28ab672b8b7297/html5/thumbnails/5.jpg)
どうすればいいか?
![Page 6: Serverspecを導入したものの放置気味な人へ](https://reader033.vdocuments.pub/reader033/viewer/2022050613/587e98db1a28ab672b8b7297/html5/thumbnails/6.jpg)
Serverspecのテストを書き続けるには
A. TDDの実践
○ サーバ/インフラ徹底攻略とかが詳しいです
B. コードレビュー時にチェック
C. ツールでテスト不足をチェック
○ テストがないAnsibleのタスクを指摘してくれる
○ 次ページ以降で紹介
![Page 7: Serverspecを導入したものの放置気味な人へ](https://reader033.vdocuments.pub/reader033/viewer/2022050613/587e98db1a28ab672b8b7297/html5/thumbnails/7.jpg)
ツールでテスト不足をチェック
● Kirby
○ Ansible用のコードカバレッジツール(拙作)
○ Playbook/Roleのタスクのうち、どれだけがServerspecで
テストされているか(=カバレッジ)がわかる
○ テストがないタスクの一覧もわかる
![Page 8: Serverspecを導入したものの放置気味な人へ](https://reader033.vdocuments.pub/reader033/viewer/2022050613/587e98db1a28ab672b8b7297/html5/thumbnails/8.jpg)
Kirbyの実行結果の例
$ ansible-playbook web.yml -i inventory (省略)TASK: [Apache2のインストール] ******************************************************** (省略)TASK: [/etc/apache2/conf-available/security.confの設定] ************************** (省略)PLAY RECAP ******************************************************************** *** Kirby Results ***Coverage : 50% (1 of 2 tasks are tested)Not tested: - /etc/apache2/conf-available/security.confの設定
*** Kirby End *******localhost : ok=2 changed=2 unreachable=0 failed=0
通常通りAnsibleを実行
カバレッジ、テストされていないタスク一覧を表示
![Page 9: Serverspecを導入したものの放置気味な人へ](https://reader033.vdocuments.pub/reader033/viewer/2022050613/587e98db1a28ab672b8b7297/html5/thumbnails/9.jpg)
Kirbyのその他の良さ
● テストになっていないテスト (下例)が見つかる
tasks: - name: Apache2のインストール
apt: pkg=apache2 state=present update_cache=yes - name: /etc/apache2/conf-available/security.confの設定
template: src=security.conf.j2 dest=/etc/apache2/conf-available/security.conf
Playbook (抜粋)
describe package('apache2') do it { should be_installed }enddescribe file('/etc/apache2/conf-available/security.conf') do it { should be_file }end
specファイル (抜粋)
![Page 10: Serverspecを導入したものの放置気味な人へ](https://reader033.vdocuments.pub/reader033/viewer/2022050613/587e98db1a28ab672b8b7297/html5/thumbnails/10.jpg)
Kirbyのその他の良さ
● テストになっていないテスト (下例)が見つかる
tasks: - name: Apache2のインストール
apt: pkg=apache2 state=present update_cache=yes - name: /etc/apache2/conf-available/security.confの設定
template: src=security.conf.j2 dest=/etc/apache2/conf-available/security.conf
Playbook (抜粋)
describe package('apache2') do it { should be_installed }enddescribe file('/etc/apache2/conf-available/security.conf') do it { should be_file }end
specファイル (抜粋)
黄枠タスクに書き間違いがあっても、発見できない→ テストとして不十分
![Page 11: Serverspecを導入したものの放置気味な人へ](https://reader033.vdocuments.pub/reader033/viewer/2022050613/587e98db1a28ab672b8b7297/html5/thumbnails/11.jpg)
Kirbyのその他の良さ
● Kirbyが見つけてくれました(ドヤ)
$ ansible-playbook web.yml -i inventory (省略)PLAY RECAP ******************************************************************** *** Kirby Results ***Coverage : 50% (1 of 2 tasks are tested)Not tested: - /etc/apache2/conf-available/security.confの設定
*** Kirby End *******localhost : ok=2 changed=2 unreachable=0 failed=0
security.conf設定タスクのテストがないことを指摘
![Page 12: Serverspecを導入したものの放置気味な人へ](https://reader033.vdocuments.pub/reader033/viewer/2022050613/587e98db1a28ab672b8b7297/html5/thumbnails/12.jpg)
Kirbyの詳細
● 以下をご確認下さい
○ GitHubページ
■ https://github.com/ks888/kirby
○ ブログ記事
■ http://ks888.hatenablog.
com/entry/2015/09/06/223538
![Page 13: Serverspecを導入したものの放置気味な人へ](https://reader033.vdocuments.pub/reader033/viewer/2022050613/587e98db1a28ab672b8b7297/html5/thumbnails/13.jpg)
まとめ
● Serverspecのテストが段々書かれなくなる問題
● 拙作ツールによる対策を紹介
○ Ansible用のコードカバレッジツールKirby
■ Ansibleのタスクのうち、テストされていないタスク一覧
がわかる
■ ご意見等、ぜひTwitter(@ks888sk)にお願いします
![Page 14: Serverspecを導入したものの放置気味な人へ](https://reader033.vdocuments.pub/reader033/viewer/2022050613/587e98db1a28ab672b8b7297/html5/thumbnails/14.jpg)
ご清聴ありがとうございました