是否可以定义在流浪者销毁之前发生的事情? [英] Is it possible to define what happens prior to vagrant destroy?

查看:84
本文介绍了是否可以定义在流浪者销毁之前发生的事情?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 Vagrantfile ,它在 vagrant上克隆了所需的菜谱库上。问题是,它也在无用销毁上执行此操作。有没有一种方法可以定义 pre-construction和 pre-destruction命令,或者每次调用vagrant时,Vagrantfile都会完全运行而与参数无关?

I have a Vagrantfile that clones the required cookbook repos on vagrant up. The problem is, it also does this on vagrant destroy. Is there a way to define 'pre-construction' and 'pre-destruction' commands or does the Vagrantfile just get run in totality each time vagrant is invoked regardless of the parameters?

推荐答案

我不知道销毁钩子,但是您可以通过检查计算机ID是否存在来检测Vagrantfile中的首次操作和后破坏操作:

I don't know about a destroy hook, but you can detect first time and post-destoy actions in the Vagrantfile by checking the existence of the machine ID:

File.exists?(".vagrant/machines/default/virtualbox/id")

我用它来插入机器的公共密钥,这使我可以自动设置安全的SSH密钥:

I use this to drop in the public key for the machine, which allows me to setup a secure SSH key automatically:

if ! File.exists?(".vagrant/machines/default/virtualbox/id")
    # Then this machine is brannd new.
    system "cp #{KEYS_DIR}/workstation.pub #{OUR_DIR}"
end

这篇关于是否可以定义在流浪者销毁之前发生的事情?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆