Reputation: 1959
I vagrant up
a project, but accidentally delete the Vagrantfile folder, the VM is still in VirtualBox, how to rebuild the vagrantfile and assign it to the same VM.
Upvotes: 1
Views: 2781
Reputation: 310
You cannot rebuild Vagrantfile. But you can associate your folder with existing vm.
Short step-by-step (based on this link):
.vagrant
$ VBoxManage list vms
in your terminal.vagrant
this code: {"active":{"default":"YOUR-ID-HERE"}}
{"active":{"default":"ec426377-dbe6-4be7-4751-766956e44958"}}
$ vagrant init
(this will create new Vagrantfile
)$ vagrant up
(this will associate your desired folder with running vm)$ ssh-keygen -t rsa -f .vagrant/machines/default/virtualbox/private_key
$ ssh-copy-id -i .vagrant/machines/default/virtualbox/private_key.pub -p 2222 [email protected]
, password: vagrant
Upvotes: 4
Reputation: 10721
I don't think there is a way to do that (create a Vagrantfile from an existing VM). From the perspective of Vagrant virtual machines being temporary in nature (build, use, destroy), you're best bet may be to recreate the Vagrantfile again and start over.
If there is something on the VM that you want or need, you could access it directly via VirtualBox, then copy over to the new VM as needed.
Upvotes: 0