我有幾本食譜,其中包括其他幾本食譜,這取決於每本食譜的需求。 附帶的食譜宣佈通知其他服務的服務。建議在包含的配方中使用return語句嗎?
其中一本食譜common_actions
包含在所有其他食譜中,因爲它包含所有人共同的操作。
include_recipe 'cookbook1'
include_recipe 'common_actions'
include_recipe 'cookbook2'
# Several cookbooks have such includes, but 'common_actions'
# is included in almost all the cookbooks.
# cookbook specific conditional logic that should be
# executed only if some condition in 'common_actions' is true
是不是一個明智的主意,包括在common_actions
菜譜條件return語句,這樣就會迫使不對其進行編譯執行的基礎/根據這一條件的,包括食譜?對於這個問題的目的,請考慮像假的條件:
if node['IP'] == 'xyz'
# All including cookbooks should execute only IP is xyz
return
end
能與這樣一個return語句原因只有特定的食譜菜譜運行?這是可取的嗎?
注意:我這樣做是因爲我不想在所有其他食譜中複製粘貼相同的代碼。