Vagrant Best Practice - Persistance - vagrant

I like how through vagrant I can spin up my machine, configure it and get to coding. However when I do vagrant halt, and then do a vagrant up again, it rebuilds my machine from the base box. All the new stuff I installed, my project repository is gone.
I can see that the virtual machine still exists in virtual box and I can use it from there, but I want to use vagrant to manage it and access it while keep the persistence of the disk as I would accessing it directly from virtual box. My host is windows, my guest is precise64.
Thoughts?
Stephen

Maybe you want to use vagrant suspend? (via)

Related

Vagrant vs VBox folder share

I have been using Vagrant for few months. Also I have started using Virtual box without Vagrant with sharing folders from host OS and it works well so far.
My question is why is Vagrant needed if Virtual Box can share folders without Vagrant?
Maybe I don't use Vagrant's other features so I don't need them so far.
Just a few things, but will probably not be exhaustive:
Vagrant operates multiple provider, not only Virtualbox, you can run vagrant with Virtualbox, VMWare, HyperV ... (docker as well even if there are different pros and cons) so vagrant abstracts this for you
vagrant can setup shared folders as you experienced, but can easily set different shared folder types (nfs, rsync ..) depending your setup
vagrant will manage all the networking of the VM, if you need a static IP, it will associate hostname and static IP and setup all the routes for you.
vagrant works well with many provisioning tools (puppet, chef, ansible ...) so you can easily create and re-created multiple times the same environment
On top of all this, why is vagrant good to use ? In team. If you work in team, you share a vagrant file (just a ruby script file) and "magically" all your team members share the same environment to work.

Is it possible to run a Vagrant box inside an Ubuntu Virtual box machine?

I currently have a windows 10 which I like for everything, except when it comes to development. So whenever I need to work, I run an Ubuntu virtual box machine and I code there.
I recently started working with a team that uses Vagrant boxes (For development environments) and Ansible (For provisioning). My question is, is it possible to run a Vagrant box inside my Ubuntu virtual machine to provision it with Ansible? (Since it is only available on Linux distros).
I realize that this is a bit confusing since I am running a virtual machine inside another. Is there any way I can go around this?
Vagrant is able to run on windows, you can set a nice directory sharing and you can access that directory from your other VM. If provision is part of the Vagrantfile, you don't have to worry whether this will work in windows or not because most of the provisioners run inside the created machine already.
For Ansible, you should use Ansible Local provisioner. That will let it run on guest machine completely and you won't need Ansible on the host machine.

Virtual machine set-up using Vagrant, but started via VirtualBox UI

Hadoop & Vagrant: If I set up a new VM using these two packages, is the VM available for starting with VirtualBox or do I always have to use vagrant up?
When you first create the VM, you will need to use vagrant up since VirtualBox has no ability to read a Vagrantfile. Once your VM is up and running, you could stop and start it using VirtualBox. However, Vagrant can perform the same operations as VirtualBox and has a lot of advantages on top of that.
First let's discuss how Vagrant can do what VirtualBox can do. You can use vagrant suspend to put the VM in a saved state, vagrant resume to start it again, vagrant halt to power it off, and vagrant destroy to delete it. You can also use settings in Vagrant's VirtualBox provider to modify your VM's memory, CPUs, and more. You can also change the network settings and synced folders. And this gives you the advantage of defining all of these settings in code which can be checked into a revision control system such as Git.
On top of all this, Vagrant has support for provisioners. These range from something as simple as shell scripts to full blown configuration management tools such as Puppet, Chef, Ansible, and Salt. Just like you can define your VM's VirtualBox settings in code, you can define the entire creation process including installing packages, managing services, and customizing files. And you can make changes at any time and apply them using vagrant provision.
So getting back to your question... yes, you can control your VM directly with VirtualBox, but you'd be missing out on the rich feature set of Vagrant.

does "vagrant destroy" erase apache configs?

I'm new to vagrant, I'm using scotchbox.
I've configured a couple of vhosts in apache.
I guess the right way to do this would have been to change the provisionning of my box (as it's the aim of vaghrant right?) but i did the old school way by simpply editing my config files and so on...
Now my question is :
if i run vagrant destroy, do i loose all my configs?
is there any other command (vagrant halt, vagrant suspend?) that would allow me to reboot my host machine without loosing my config?
vagrant destroy will remove entire VM so any changes that were made manually will be lost. Vagrant halt only turns of the power so to speak so nothing is lost. If you run your machine again or reboot it all your data is save, just don't use --provision option that will recreate all initial configuration.

Is it possible to export/import a virtual box machine in one file?

I have a Vagrant set up with 3 virtual machines. Each machine has its own shell script for provisioning.
Now I would like to share the exact same status of my set up with somebody else. Since the provisioning procedure takes really (!!) long for each machine, I hope there is another solution.
Ideally I would be able to save each machine as it is in one file, which the other person then could import into Virtualbox. Is there a way to do that?
If I understand you correctly you would like to make a Vagrant base box from provisioned by Vagrant VMs. This is not recommended way to go. How you can approach this is:
Create new VM manually with required OS in the VBox.
Adjust it so Vagrant can connect to it as described here and here.
Provision it using your shell scripts.
Install all the things you would find useful to have on this VM.
Use Vagrant to package it as a base box as described here.
After packaging it with Vagrant you will get a Vagrant base box file with .box extension. You can then pass this to your team mates (usb, network share, ftp etc.) and they can add it to their Vagrant installation and use it. Whenever they will do Vagrant up they will get fully provisioned VM in VBox with all the stuff you have packaged to it. Vagrant also gives you versioning capabilities. If properly configured whenever you will create new version of base box everybody who is using it will be notified and would be able to download and use new version of your box.
Hope I understood your problem correctly and this will help to solve it.

Resources