如何在“vagrant destroy”上运行 Vagrant 任务?

joh*_*dev 2 virtualbox vagrant

我正在运行 Vagrant width Virtualbox,我想知道是否有办法在销毁机器(vagrant destroy)时执行 vagrant 任务?就像您在配置 ex 上运行任务时一样:

config.vm.provision "shell" do |s|,
    s.inline: "echo Hello, World"
end
Run Code Online (Sandbox Code Playgroud)

先感谢您!

For*_*ier 5

就像乔恩·斯特林在评论中所说的那样。 Vagrant 触发器是您有点令人困惑的问题的答案。无论如何,使用触发器您可以在销毁发生之前和之后添加触发器。

例如:

Vagrant.configure("2") do |config|
  # Your existing Vagrant configuration
  config.trigger.before :destroy do
    run "rm -Rf tmp/*"
  end
end
Run Code Online (Sandbox Code Playgroud)