如何在厨师运行期间动态编辑模板文件
我的厨师食谱中有一个名为“测试模板”的模板文件,在我的厨师食谱中,我正在将模板文件采购并更新为文件“/etc/run/mn.txt”,如下所示:
template 'Test Template' do
source 'run.config'
path /etc/run/mn.txt
end
我需要更新此模板文件在调用上述“模板”资源之前,在 Chef 运行期间动态地执行此操作。在调用模板资源之前,如何在我的食谱中编辑模板文件本身?我需要这样做,因为我要向模板文件中添加一些行,如果我随后将这些行添加到此资源块之后创建的文件中,则在下一次厨师客户端运行期间它将恢复为原始模板内容。
I have a template file in my chef cookbook named 'Test Template', In my Chef recipe I am sourcing and updating my template file to a file '/etc/run/mn.txt' as follows:
template 'Test Template' do
source 'run.config'
path /etc/run/mn.txt
end
I need to update this template file dynamically during the chef run before the above "template" resource is called. How can I edit the template file itself within my cookbook before the template resource is called? I need to do this because there are lines I am adding to the template file and if I add the lines afterward to the created file after this resource block, it will just get reverted back to the original template contents during the next chef-client run.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您知道在执行模板资源之前要在
/etc/run/mn.txt
中包含哪些内容吗?如果是这样,您可以使用变量属性(传递到 Ruby 模板文件的变量的哈希值)将内容推送到/etc/run/mn.txt
文件中:然后在您的run.config,您可以在末尾添加类似以下内容:(
或者您可以向变量参数传递哈希值,并通过模板中的哈希键进行某种循环......以使其更加动态)
Do you know the contents that you want to include in
/etc/run/mn.txt
before the template resource is executed? If so, you can use the variables property (A Hash of variables that are passed into a Ruby template file) to push the contents into the/etc/run/mn.txt
file:And then in your run.config, you could add to the end something like:
(Or you could pass the variables parameter a hash, and do some sort of loop through the hash keys in your template.. to make it more dynamic)