0
を取っていない上書き属性:(1)レシピにオーバーライドだとレシピに使用されているシェフは、私が定義されたデフォルトの属性を持っている効果
/cookbook-test/attributes/default.rb
## Environemnt attributes
default['cookbook-test']['flags']['test']="dummy_flag"
(2)レシピに
/cookbook-test/recipes/default.rb
include_recipe 'cookbook-test::set-flag-based-on-file' #(1)
#...
include_recipe 'cookbook-test::other-recipe' # (2) this recipe needs the attribute
こと属性がオーバーライドされている(1)場合、属性はファイルの内容に応じて変化します。
/cookbook-test/recipes/set-flag-based-on-file.rb
ruby_block "Use attribute (A/B)" do
block do
# reads file for flag "A"/"B"
local_flag= ::File.read('/home/user/.flag').chomp
if local_flag== "A"
node.set['cookbook-test']['flags']['test'] = true
elsif local_flag== "B"
node.set['cookbook-test']['flags']['test'] = false
else
node.set['cookbook-test']['flags']['test'] = false
end
end
end
ここでr ecipe(2)は、属性を使用しようとしている:
/cookbook-test/recipes/other-recipe.rb
flag= node['cookbook-test']['flags']['test']
if flag == true
# something
elsif flag == false
# something
else
Chef::Log.error("XX attribute is not SET!")
end
しかしとき料理が実行され、それがレシピそれが上書きされることはなかったと(2)の値がまだ「dummy_flag」に設定されていることを得ます。私は "node.force_default
"で属性を設定しようとしましたが、成功しませんでした。 「A」の旗を持つファイルが効果を持つされていない持っ
も、属性が正しくオーバーライドするために、私は、何をしないのです
var/chef/log/client.log
...
[2017-02-09T12:56:06-05:00] ERROR: XX attribute is not SET!
...
...ファイルが正しく読み込まれていると思いましたか?
シェフは注文を保証しますが、それはあなたがそれと思った順序ではありません。概要はhttps://coderanger.net/two-passをご覧ください:) – coderanger
リンクありがとうございます:) – david