简体   繁体   English

如果源模板发生更改,要执行的厨师模板资源?

[英]Chef template resource to execute if the source template changes?

I'm deploying a package that requires a template be created in a specified directory every time a directory is unzipped. 我正在部署一个程序包,该程序包要求在每次解压缩目录时都在指定的目录中创建一个模板。

A remote_file notifies my unzip action, that unzip action notifies the template resource, which in turn notifies other resources. 一个remote_file通知我的解压缩操作,该解压缩操作通知模板资源,模板资源又通知其他资源。 This chain of notifications works as expected. 此通知链按预期工作。

Below is my template resource: 以下是我的模板资源:

template 'C:\\Program Files\\MyProgram\\program.yml' do
  source "my_program-#{node['program']['version']}.yml.erb"
  action   :nothing
  notifies :run, 'powershell_script[install-program]', :immediately
end

My question: Is there a way to have the template resource execute if I make a change to the source template? 我的问题:如果对源模板进行更改,是否可以使template资源执行? Right now it only executes the template resource if notified by my unzip action (due to my action :nothing ). 现在,它仅在我的解压缩操作通知(由于我的action :nothing )时才执行template资源。

However, it would be great to have a way for it to tell if the template itself has changed. 但是,最好有一种方法可以告诉它模板本身是否已更改。 Perhaps some kind of not_if or only_if statement? 也许某种not_ifonly_if语句?

sounds to me that you avoid all the notification chaining if you will have your resources defined in the same recipe. 在我看来,如果您在同一配方中定义了资源,则可以避免所有通知链接。

back to your questions, it sounds that setting action :create , which is the default action, will do the trick. 回到您的问题,听起来好像设置action :create (这是默认动作)可以解决问题。 from the template resource documentation 模板资源文档中

action :create 动作:创建

Create a file. 创建一个文件。 If a file already exists (but does not match), update that file to match. 如果文件已存在(但不匹配),请更新该文件以使其匹配。

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

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