从字符串生成文件而不必在Chef中创建模板文件? [英] Generate a file from a string without having to create a template file in Chef?
本文介绍了从字符串生成文件而不必在Chef中创建模板文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我目前在食谱中使用以下代码:
I currently use this code in a recipe:
template "/var/django/.ssh/id_rsa" do
source "id_rsa.erb"
owner "django"
group "django"
variables :key => ssh_key
mode 00600
end
这是 id_rsa.erb
看起来像:
<%= @key %>
我想知道是否可以避免使用模板,而只是从字符串中生成文件。也许是这样的:
I was wondering if I could avoid having a template, and simply produce the file from the string. Something like this perhaps:
file_from_string "/var/django/.ssh/id_rsa" do
source ssh_key
owner "django"
group "django"
mode 00600
end
推荐答案
使用 file
资源并将文件内容指定为 content
属性。
在您的情况下,这将导致类似于以下的资源定义:
In your case, this would result in a resource definition similar to this:
file "/var/django/.ssh/id_rsa" do
content ssh_key
owner "django"
group "django"
mode 00600
end
这篇关于从字符串生成文件而不必在Chef中创建模板文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文