我正在试图在一个包含的文件中使用一个局部variables。 我得到的是没有定义的错误。 我不确定一个这样做的方法,是吗? 我有一个配方文件夹:
recipes/ development.rb testing.rb config.rb
development.rb
username = "vagrant" static = [] django = ["project1", "project2"] include_recipe "server::config" # <-- Trying to use static and django in there.
config.rb
static.each do |vhost| # <-- How do I get the "static" var in here? ... end django.each do |vhost| # <-- How do I get the "django" var in here? ... end
您不能在食谱之间共享variables,但有两种方法可以在食谱之间共享数据。
attributes/default.rb中将static和django作为属性外部化。 这意味着它们将在node对象上可用,并可从每个配方访问。 属性/ default.rb
default["server"]["static"] = [] default["server"]["django] = ["project1", "project2"]
食谱/ config.rb
node["server"]["static"].each do |vhost| ... end node["server"]["django"].each do |vhost| ... end
我的build议是绝对坚持select一,这是最常见的方法。 希望有所帮助!
在这个晚会上有点晚了,我认为可以接受的解决scheme是这里的首选,但是…
可以在“父”配方中设置一个variables,并通过修改节点(例如,
node.default['django'] = ["project1", "project2"]
在过去,我曾经做过这样的事情,我希望辅助程序的配方在从不同的“父”配方调用时performance得有些不同,即根据从属性访问稍微不同的一组configuration来安装不同的git repo。
至于这是否是最佳实践,我欢迎评论,但似乎比编写资源来包装git lwrp更容易。