よく利用するコマンドをgitoliteとBerkshelfで管理
よく利用するコマンドやパッケージをcookbook化し、プライベートリポジトリ(gitolite)で管理してます。
Berkselfを使ってプライベートリポジトリからcookbookを取得しています。
- Berksfile
site :opscode cookbook "yum" cookbook "rbenv", git: "git://github.com/RiotGames/rbenv-cookbook.git" cookbook "td-agent", git: "https://github.com/treasure-data/chef-td-agent.git" cookbook "base-cookbooks", git: "ssh://gitolite-cookbooks/base-cookbooks", protocol: :ssh cookbook "sysstat", git: "ssh://gitolite-cookbooks/sysstat", protocol: :ssh cookbook "bind-util", git: "ssh://gitolite-cookbooks/bind-util", protocol: :ssh cookbook "git", git: "ssh://gitolite-cookbooks/git", protocol: :ssh cookbook "ntp", git: "ssh://gitolite-cookbooks/ntp", protocol: :ssh cookbook "unzip", git: "ssh://gitolite-cookbooks/unzip", protocol: :ssh cookbook "curl", git: "ssh://gitolite-cookbooks/curl", protocol: :ssh cookbook "elinks", git: "ssh://gitolite-cookbooks/elinks", protocol: :ssh cookbook "nkf", git: "ssh://gitolite-cookbooks/nkf", protocol: :ssh cookbook "dstat", git: "ssh://gitolite-cookbooks/dstat", protocol: :ssh cookbook "wget", git: "ssh://gitolite-cookbooks/wget", protocol: :ssh cookbook "subversion", git: "ssh://gitolite-cookbooks/subversion", protocol: :ssh cookbook "mlocate", git: "ssh://gitolite-cookbooks/mlocate", protocol: :ssh cookbook "ssh", git: "ssh://gitolite-cookbooks/ssh", protocol: :ssh cookbook "rbenv_install", git: "ssh://gitolite-cookbooks/rbenv_install", protocol: :ssh cookbook "tcpdump", git: "ssh://gitolite-cookbooks/tcpdump", protocol: :ssh cookbook "telnet", git: "ssh://gitolite-cookbooks/telnet", protocol: :ssh cookbook "yumdownloader", git: "ssh://gitolite-cookbooks/yumdownloader", protocol: :ssh cookbook "man", git: "ssh://gitolite-cookbooks/man", protocol: :ssh cookbook "nc", git: "ssh://gitolite-cookbooks/nc", protocol: :ssh cookbook "htop", git: "ssh://gitolite-cookbooks/htop", protocol: :ssh cookbook "tmpwatch", git: "ssh://gitolite-cookbooks/tmpwatch", protocol: :ssh cookbook "top", git: "ssh://gitolite-cookbooks/top", protocol: :ssh cookbook "gdb", git: "ssh://gitolite-cookbooks/gdb", protocol: :ssh cookbook "iotop", git: "ssh://gitolite-cookbooks/iotop", protocol: :ssh cookbook "strace", git: "ssh://gitolite-cookbooks/strace", protocol: :ssh cookbook "monit", git: "ssh://gitolite-cookbooks/monit", protocol: :ssh cookbook "clamav", git: "ssh://gitolite-cookbooks/clamav", protocol: :ssh cookbook "mailx", git: "ssh://gitolite-cookbooks/mailx", protocol: :ssh
- cookbookのインストール
berks install --path cookbooks
- 共通cookbookの適用
NodeまたはRoleに共通cookbook名だけ記述します。
"recipe[base-cookbooks]"
base-cookbooksの中身
include_recipe "bind-util" include_recipe "sysstat" include_recipe "dstat" include_recipe "git" include_recipe "subversion" include_recipe "ntp" include_recipe "unzip" include_recipe "wget" include_recipe "curl" include_recipe "nkf" include_recipe "elinks" include_recipe "telnet" include_recipe "tcpdump" include_recipe "mlocate" include_recipe "yumdownloader" include_recipe "man" include_recipe "nc" include_recipe "htop" include_recipe "tmpwatch" include_recipe "strace" include_recipe "monit" include_recipe "clamav" include_recipe "mailx" include_recipe "td-agent"
共通cookbook内にincludeしているcookbookを修正した時は
berks update && berks install --path cookbooksで更新します。
※数カ月ぶりに共通cookbookを動かしたところ、 内部で利用しているopscodeから取得したyum cookbookが2系 -> 3系にバージョンが上がっていて これに依存指定している自分のレシピが動かなかったという罠。
opscodeから取得するcookbook(にかぎらずですが)をBerkselfで取得する時は、バージョンを固定するか、
最新バージョンのcookbookを動かしてエラーを吐いた場合はすみやかに修正しましょう。
作りっぱなしは不幸を生むだけ。定期的なメンテナンスを怠るな。
Jenkins+vagrant等で定期的にレシピをぶん回すのが気づきへの近道かも?
おわり。