我如何通知厨师执行需要参数的资源

How do i notify a chef execute resource that require a parameter

我正在尝试从 remote_file 资源中通知下面的执行资源并且需要传递应用程序名称。我该怎么做?

execute "rm -rf /opt/app/#{application['name']}.zip" do 
  action: nothing
end

除了可以使用目录资源删除外,没有任何参数。在您的情况下,资源名称是 execute[rm -rf /opt/app/#{application['name']}.zip],您必须使用此名称通知它:

some_resource "foo" do
  whatever true
  notifies :run, "execute[rm -rf /opt/app/#{application['name']}.zip]"
end

对于名称为 test 的应用程序,资源名称将为 execute[rm -rf /opt/app/test.zip]

除上述之外,您还可以为资源起一个更简洁的名称:

execute 'delete_files' do
  command "rm -rf /opt/app/#{application['name']}.zip"
  action :nothing
end

some_resource 'foo' do
  whatever true
  notifies :run, 'execute[delete_files]'
end