如何在Chef中编写带有外部cookbook_files的食谱?(How to write a cookbook with external cookbook_files in Chef?)
如何创建一个通用的食谱,允许用户指定将被复制的cookbook_file的位置? 我想这个文件是一个可覆盖的属性。
例如:创建一个nginx cookbook,用户可以在其中指定SSL文件的位置,以便它可以将这些文件复制到服务器中的正确目录中。
How do you create a general cookbook where you allow users to specify a location of a cookbook_file that will be copied? I'd imagine this file to be an overridable attribute.
For example: create an nginx cookbook where the user can specify where the SSL files are so that it can copy these files into the right directory in the server.
原文:https://stackoverflow.com/questions/14067637
最满意答案
如果您希望通过
cookbook_file
资源访问该files
,则该文件应位于cookbook的files
子目录中。 如果要从其他位置获取文件,则需要使用remote_file
。 (不要在你的食谱中设置node[:nginx][:ssl_file_location]
。)cookbook_file filename do [...] only_if { node[:nginx][:ssl_file_location].nil? } end remote_file ::File.join( node[:nginx][:ssl_file_location].to_s, filename ) do [...] not_if { node[:nginx][:ssl_file_location].nil? } end
当需要设置ssl_file_location时,他可以创建一个attributes.json文件:
{ "nginx": { "ssl_file_location" : "[my location]" } }
并运行厨师客户:
chef-client --json-attributes attributes.json
编辑:
如果ssh_files实际上在其他一些食谱中,那么你可以使用cookbook_file,但你必须提供这样的cookbook属性:
cookbook_file filename do [...] cookbook 'cookbook_name_where_to_look' end
A file should be in
files
subdirectory of the cookbook, if you want it to be accessible throughcookbook_file
resource. If you want to get the file from somewhere else, you need to useremote_file
. (Do not setnode[:nginx][:ssl_file_location]
in your cookbook.)cookbook_file filename do [...] only_if { node[:nginx][:ssl_file_location].nil? } end remote_file ::File.join( node[:nginx][:ssl_file_location].to_s, filename ) do [...] not_if { node[:nginx][:ssl_file_location].nil? } end
When one needs to set ssl_file_location, he can create a attributes.json file:
{ "nginx": { "ssl_file_location" : "[my location]" } }
and run chef client:
chef-client --json-attributes attributes.json
Edit:
If ssh_files are actually in some other cookbook, then you can use cookbook_file, but you must provide cookbook attribute like that:
cookbook_file filename do [...] cookbook 'cookbook_name_where_to_look' end
相关问答
更多-
docker cookbook不提供任何配方,这就是为什么您的include_recipe调用失败。 相反,您只需使用资源,就像您已经拥有docker_service资源一样。 在删除三条include_recipe行时,应该运行你的配方。 The docker cookbook does not provide any recipes, which is why your include_recipe calls fail. Instead, you just use the resources, lik ...
-
我有一个原始的别名“上传”, knife cookbook upload ${PWD##*/} -o ..这将上传当前的食谱。 我的目录名称与metadata.rb中定义的cookbook名称相匹配,我只从cookbook的根目录运行它,因此它足以支持我的工作流程。 I have a primitive alias "upload" that does knife cookbook upload ${PWD##*/} -o .. which will upload the current cookbook. ...
-
简短回答是的。 你应该使用shell_out!('python -V').stdout().chomp()而不是反引号。 但是信息已经存在于节点自动属性中,因此您不必调用python -V : ohai languages回归: { "python": { "version": "2.7.3", "builddate": "Jun 22 2015, 19:33:41" }, "perl": { "version": "5.14.2", "archname": "x ...
-
那么,对于所描述的用例,我会做同样的事情。 Well, for the described use case, I would do the exact same.
-
有AFAIK没有“好/干净”的方式来复制包含在食谱中的所有文件。 为了创建多个文件,你可以应用简单的ruby逻辑来遍历这些文件: ['a.txt', 'b.txt'].each do |file| cookbook_file "/home/user/work/somelocation/#{file}" do source "folder-name/#{file}" mode "0644" end end 这将创建多个cookbook_file资源( @jamesgaddum正在谈论 ...
-
我最近遇到了同样的问题。 因为chefspec旨在快速且仅模拟厨师运行,所以它不会从厨师服务器克隆烹饪书。 它要求chef_handler食谱需要是本地的。 默认情况下,它会在与您正在测试的食谱相同的级别上查找它。 例如 ./test_cookbook ./chef_handler I ran into the same problem recently. Because chefspec aims to be fast and only simulate chef runs, it doesn't cl ...
-
如何在Chef中编写带有外部cookbook_files的食谱?(How to write a cookbook with external cookbook_files in Chef?)[2021-08-09]
如果您希望通过cookbook_file资源访问该files ,则该文件应位于cookbook的files子目录中。 如果要从其他位置获取文件,则需要使用remote_file 。 (不要在你的食谱中设置node[:nginx][:ssl_file_location] 。) cookbook_file filename do [...] only_if { node[:nginx][:ssl_file_location].nil? } end remote_file ::File.join( no ... -
测试Chef cookbook失败(Testing Chef cookbook failure)[2021-08-12]
要测试custom_resource的内部位,您必须告诉ChefSpec step_into它。 你是对的ChefSpec在正常情况下不会执行提供程序。 要对失败进行适当的测试,您应该expect(:chef_run).to raise_error ,如文档中所述 step_into文档的step_into : 为了运行LWRP公开的操作,您必须明确告诉Runner进入它: 要求'chefspec' describe 'foo::default' do let(:chef_run) do Che ... -
您需要使用像berks vendor这样的东西来写出完整的cookbook文件夹,然后将Packer作为目标。 You would need to use something like berks vendor to write out the full cookbook folder and then aim Packer at that.
-
无法在厨师中安装食谱(Unable to install cookbook in chef)[2021-10-17]
你必须 > git add --all > git commit -a -m "updates" > git stash save 您必须查看https://docs.chef.io/errors.html You must > git add --all > git commit -a -m "updates" > git stash save You must view https://docs.chef.io/errors.html