调用LWRP时的菜谱名称前缀 [英] Cookbook name prefix when calling LWRP
问题描述
我可以使用外部食谱中的LWRP而不添加食谱名称吗?例如,如果 mycookbook
包含 mylwrp
资源,我该怎么做?
Can I use an LWRP from an external cookbook without prefixing the cookbooks name? For example, if mycookbook
contains the mylwrp
resource how can I do this?
include_recipe 'mycookbook' # Contains "mylwrp"
mylwrp "frobulator" do
frobulations 42
end
详细信息
我写了一个LWRP,名称为 mycookbook_mylwrp
,因为图书馆食谱使用正常的资源/提供商布局,如下所示:
Details
I have written an LWRP that gets the name mycookbook_mylwrp
since the library cookbook uses the normal resources/provider layout as follows
mycookbook/
├── providers
│ └── mylwrp.rb
└── resources
└── mylwrp.rb
是否有可能
- 将LWRP保留在
mycookbook
Cookbook - 使用LWRP时不带
mycookbook
名称(mycookbook_mylwrp
)
- Keep the LWRP in the
mycookbook
cookbook - Use the LWRP without prefixing the
mycookbook
name (mycookbook_mylwrp
)
我意识到我可以创建一个全新的食谱,并将其称为 mylwrp ,并按如下所示使用默认提供程序
I realise that I can create a whole new cookbook and call it "mylwrp" and use the default providers as follows
mylwrp/
├── providers
│ └── default.rb
└── resources
└── default.rb
但是我必须为要以这种方式使用的每个LWRP制作专用的食谱。
but then I have to make dedicated cookbooks for each LWRP I want to use in this manner.
推荐答案
一种选择是使用HWRP。这些位于库
目录中,而不是资源
和提供者
。如果您走这条路,我会考虑使用 poise
库,该库可让您编写与LWRP具有相同技巧的HWRP。
One option is to use HWRPs. These go in the libraries
directory rather than resources
and providers
. If you go that route, I'd look into the poise
library which allows you to write HWRPs with the same finesse as LWRPs.
现在,所有这些,您正在做的事情肯定超出了常规。社区用于自定义提供者的名称空间,以匹配声明它们的食谱。如果您想与社区共享此食谱,将会引起一些混乱。即使您仅在内部使用它,它也会使您带入团队的任何新成员的学习曲线都更加陡峭。因此,除非您有充分的理由这样做,否则我强烈建议您避免这样做。
Now, all that said, you are doing something that is decidedly outside the norm. The community is used to custom providers being namespaced to match the cookbook that declares them. If you want to share this cookbook with the community, you're going to cause some confusion. Even if you only use it internally, it will steepen the learning curve for any new members you bring onto your team. So unless you have a compelling reason to do it, I'd strongly suggest you avoid it.
另一方面,如果您确实有强迫的理由,建议您分享一下,以便我们都能从您的想法中受益。
On the other hand, if you do have a compeling reason, I'd suggest you share it so we can all benefit from your thoughts.
这篇关于调用LWRP时的菜谱名称前缀的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!