0
我有限定的默認屬性:廚師屬性重寫未生效
/cookbook-test/attributes/default.rb
## Environemnt attributes
default['cookbook-test']['flags']['test']="dummy_flag"
這重寫上的配方(1)和上配方被使用(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