gpt4 book ai didi

chef-infra - 如何在 Chef 中使用外部 cookbook_files 编写 Recipe ?

转载 作者:行者123 更新时间:2023-12-05 01:13:10 25 4
gpt4 key购买 nike

如何创建通用说明书,让用户指定要复制的说明书文件的位置?我想这个文件是一个可覆盖的属性。

例如:创建一个 nginx 说明书,用户可以在其中指定 SSL 文件的位置,以便它可以将这些文件复制到服务器中的正确目录中。

最佳答案

如果您希望通过cookbook_file 资源访问该文件,则该文件应位于 Recipe 的files 子目录中。如果你想从其他地方获取文件,你需要使用remote_file。 (不要在你的 Recipe 中设置 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 客户端:

chef-client --json-attributes attributes.json

编辑:

如果 ssh_files 实际上在其他一些 cookbook 中,那么你可以使用 cookbook_file,但你必须像这样提供 cookbook 属性:

cookbook_file filename do
[...]
cookbook 'cookbook_name_where_to_look'
end

关于chef-infra - 如何在 Chef 中使用外部 cookbook_files 编写 Recipe ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14067637/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com