【发布时间】:2015-03-17 01:45:05
【问题描述】:
我正在尝试从食谱“a”的食谱“A”访问食谱“b”的食谱“B”中的方法。我使用 include_recipe 'cookbook::recipe' 将食谱'B' 包含在食谱'A' 中。
#cookbook Flower
#chef recipe 'Rose' DSL
def method_to_be_called
do something
end
#cookbook Animal
#chef recipe 'Tiger' DSL
include_recipe "Flower::Rose"
#call method_to_be_called of 'Rose' recipe
end
我正在学习 Ruby 和 Chef DSL,因此我不知道我想要实现的目标是否可行。如果是,我该如何调用该方法? 提前致谢。
【问题讨论】:
-
您好,欢迎来到 Stack Overflow。仅从对代码的口头描述中很难弄清楚您要做什么。相反,您能否编辑您的问题并将相关的代码部分添加到其中? (不要只在cmets中回复,因为代码格式很糟糕)
-
感谢您的快速回复。我已经编辑了问题。
-
您不应该在配方中定义方法。为此提供了库。 docs.chef.io/libraries.html
-
谢谢。我可以知道为什么不建议在配方中不定义方法的原因吗?
标签: ruby chef-infra chef-recipe