ChefのAttribute:複数ファイルで扱い

今回はChefのAttributeについて。

Attribute = 属性 ですね。

自分の中では変数として考えています。
テンプレートファイルとかで毎回ドメイン名とか指定するのは面倒なんで。

ではファイルの種類は「.rb」rubyのファイルです。
書き方は以下の通りです。
default['test'] = 'test'
もしくは
node.default['test'] = 'test'
です。

では本題のAttributeで複数ファイルがあった場合のどうなるのかについて。

site-cookbook/ [ cookbook名 ] /attribute/default.rb
default['def'] = "def_def"
default['foo']  = "def_foo"
default['hoge']  = "def_hoge"
site-cookbook/ [ cookbook名 ] /attribute/test.rb
default['test'] = "test_test"
default['foo'] = "test_foo"
default['hoge']  = "test_hoge"

ここでchefを実行すると。
出力結果。( recipe/default.rb  && recipe/test.rb )

	def	  : def_def
test   : test_test
foo   : test_foo
hoge : test_hoge
になってしまった。

自分のイメージでは
recipe/default.rb → /attribute/default.rb
recipe/test.rb → /attribute/test.rb
Recipeに見合ったAttributeの設定のみ読み込むと勘違いしてました。

overrideを利用してみた。

overrideはどんな風になるだろう?
site-cookbook/ [ cookbook名 ] /attribute/default.rbを変更。
default['def'] = "def_def"
default['foo']  = "def_foo"
default['hoge']  = "def_hoge"
override['hoge']  = "over_hoge"
出力結果 ( recipe/default.rb  && recipe/test.rb )
	def	  : def_def
test   : test_test
foo   : test_foo
hoge : over_hoge

おおおw
defaultのoverrideが勝っているみたいですね。
なるほど。

感想
recipe/default.rbで使用されるAttributeは /attribute/default.rb の宣言のみと思っていたが
/attribute/に存在する全てのAttributeの宣言が含まれるそうだ。
また、上書きされるみたいなので注意が必要だ。 
と言いますかAttribute名が被らなければ問題ないですね。