LoginSignup
0
0

More than 5 years have passed since last update.

Chefのattributeをレシピで設定する書式

Last updated at Posted at 2018-06-04

attributeは、通常cookbookのattributesディレクトリーの下などに置くが、レシピにも書ける。
ただ、記述方法が若干特殊で、default[]などでは無く、node.default[]の様に記述する。

recipes/default.rb

# recipeで指定する際には、node.default[]の様にする。
# attributeに持って行く際には、node.を取ってdefault[]の様にする。
node.default[cookbook_name]['編集']['file']['/tmp/test.txt']['content'] = "abc\n"
node.default[cookbook_name]['編集']['file']['/tmp/test.txt']['mode'] = '755'
node.default[cookbook_name]['編集']['file']['/tmp/test2.txt']['content'] = "def\n"

...


hash = node[cookbook_name]['編集']
hash['file'].each do |f_name, f_attr|
  file f_name do
    content f_attr['content'] if f_attr['content']
    mode    f_attr['mode']    if f_attr['mode']
  end
end

参考

About Attributes
Chef社のattributesのページ
改めて見ると、いろいろ拡張されていますね。black_list, white_list, rm,..

0
0
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
0
0