Generate a file from a string without having to create a template file in Chef?

被刻印的时光 ゝ 提交于 2019-12-08 14:35:58

问题


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

And here's what id_rsa.erb looks like:

<%= @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

回答1:


Use the file resource and specify the file contents to the content property.

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


来源:https://stackoverflow.com/questions/15292579/generate-a-file-from-a-string-without-having-to-create-a-template-file-in-chef

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!