...
jenkins Cookbook を Attribute に対応させる
何を Attribute にするか
Cookbook の設計次第で何を Attribute にするかは変わりますが、
今回は次の項目を Attribute にしてみましょう。
Jenkins のバージョン
特定のバージョンの Jenkins をインストールしたくなったときに、Recipe を直したくない
同じ Recipe で複数のバージョンの Jenkins をインストールできるようにしておきたい
Jenkins の rpm ファイルの URL
将来的に rpm ファイルの URL が変更されたときに、Recipe を直したくない
Jenkins の実行ユーザー
プロビジョン先のサーバーによっては実行ユーザーを変えないといけないかもしれない
ヒント
Attribute の名前
一般的には、以下のように node[<Cookbook 名>][<任意の Attribute 名>] とすることが多いようです。
コード ブロック | ||
---|---|---|
| ||
attributes:
<Cookbook 名>:
<任意の Attribute 名>: |
Recipe では cookbook_name Method [ http://docs.opscode.com/dsl_recipe_method_cookbook_name.html ] を用いることで、自身の Cookbook 名を取得することもできます。
コード ブロック |
---|
value = node[cookbook_name]['attribute'] |
※ ./attribute/default.rb では cookbook_name Method を使用できません。
Kitchen で確認
Attribute への対応が完了したら、.kitchen.yml を編集し、Kitchen インスタンスで動作チェックをしてみましょう。