简体   繁体   English

如何在配方中使用databag的内容创建文件

[英]How to create a file with databag's contents within a recipe

My issue is on how to create or parse a databag content into a file in a recipe. 我的问题是如何在配方中将数据袋内容创建或解析为文件。 I want to use that file to authenticate the "wal-e" application. 我想使用该文件来验证“ wal-e”应用程序。

This is a draft in my mine can anyone help me to see more example or add syntax's 这是我的草稿,任何人都可以帮助我查看更多示例或添加语法的

 file "/etc/wal-e.d/env" do
   AWS_ACCESS_KEY_ID aws['access']
   AWS_SECRET_ACCESS_KEY aws['secret']
   WALE_S3_PREFIX "#{node['fc_db']['s3']['wale_s3_prefix']}"
 action :create
 end

Thanks, 谢谢,

One idea i have is the following. 我有一个想法是以下。

 directory "/etc/wal-e.d" do
   owner "postgres"
   group "postgres"
   mode 00755
   action :create
 end

 directory "/etc/wal-e.d/env" do
   owner "postgres"
   group "postgres"
   mode 00755
   action :create
 end

 aws = data_bag_item('aws', 'keys')

 file "/etc/wal-e.d/env/AWS_SECRET_ACCESS_KEY" do
   variables(:AWS_SECRET_ACCESS_KEY => aws['secret'])
   owner "postgres"
   mode  "0644"
   action :create
 end

 file "/etc/wal-e.d/env/AWS_ACCESS_KEY_ID" do
   variables(:AWS_ACCESS_KEY_ID => aws['access'])
   owner "postgres"
   mode  "0644"
   action :create
 end

 file "/etc/wal-e.d/env/WALE_S3_PREFIX" do
   variables(:WALE_S3_PREFIX => "#{node['fc_db']['s3']['wale_s3_prefix']}")
   owner "postgres"
   mode  "0644"
   action :create
 end

I have fix this by writingthe ff: 我已经通过写ff解决了这个问题:

 aws = data_bag_item('aws', 'keys')

 template "/path/to/file/AWS_SECRET_ACCESS_KEY" do
   owner "postgres"
   mode 0644
   source "AWS_SECRET_ACCESS_KEY.erb"
   variables(:AWS_SECRET_ACCESS_KEY => aws['secret'])
   action :create
 end

 template "/path/to/file//AWS_ACCESS_KEY_ID" do
   owner "postgres"
   mode  0644
   source "AWS_ACCESS_KEY_ID.erb"
   variables(:AWS_ACCESS_KEY_ID => aws['access'])
   action :create
 end

 template "/path/to/file//WALE_S3_PREFIX" do
   owner "postgres"
   mode  0644
   source "WALE_S3_PREFIX.erb"
   action :create
 end

In here the value of the databag is parse in the file so i can use them as my application need it. 在这里,databag的值在文件中进行解析,因此我可以根据需要使用它们。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM