我有几本食谱,其中包括其他几本食谱,这取决于每本食谱的需求。 附带的食谱宣布通知其他服务的服务。建议在包含的配方中使用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语句原因只有特定的食谱菜谱运行?这是可取的吗?
注意:我这样做是因为我不想在所有其他食谱中复制粘贴相同的代码。