50
48

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

include_recipeだけでは読み込み先のattributesが読み込まれない

Last updated at Posted at 2013-10-21

クックブックAとBがあり、Aのレシピ内でBのデフォルトレシピを実行してほしいのでをinclude_recipeで読み込む

A/recipes/default.rb
include_recipe "B"

クックブックBのattributesには、default.rbがあり

B/attributes/default.rb
default['B']['attr_key'] = 'attr_value'

が定義されており、レシピには

B/recipes/default.rb
#{node['B']['attr_key']}

として値を使っている。

この状態でクックブックAを実行すると、

#{node['B']['attr_key']}

のところで

NoMethodError

undefined method `[]' for nil:NilClass

というエラーになる。

解決するためには、クックブックAのmetadata.rbに

A/metadata.rb
depends "B"

と書いて依存関係を明確にすることで、実行時にBのattributesが読み込まれるようになる。

参考:
Chef does not read attributes and definitions - Stack Overflow

[#CHEF-3893] does "depend" is required in metadata.rb if you include_recipe - Opscode Open Source Ticket Tracking

50
48
0

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
50
48

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?