Will "vagrant box update" destroy my current VM? - vagrant

as described on the title, will vagrant box update destroy my current VM? My current vagrant VM is a little too fragile and needs some time to setup after it has been destroyed.
On each vagrant up I get a message, that a newer version of my base box is available, but I hesitate to do so, because I need the current setup of my VM for daily work.
Am I safe to update?

short answer is no vagrant box update only downloads and installs the new box it will NOT update any of your running Vagrant VMs.
You get the "new version box" message because check for updates on vagrant up is enabled by default. If you don't want to see it you can modify your Vagrant file by adding following line
config.vm.box_check_update = false
You have to explicitly destroy your machine and recreate it to use the updated box. Vagrant will NOT do that on its own.

Related

How can I programatically download the vagrant box(es) specified in my Vagrantfile?

I have some automatically generated Vagrantfiles and I am trying to script some Vagrant actions. Specifically, I want to automate the process of only downloading the boxes specified in a Vagrantfile, i.e. doing what vagrant box add does but without needing to specify the name or URL of the box as an argument.
Assuming I have a folder with a Vagrantfile in it, and a copy of the box has not yet been downloaded:
vagrant up downloads the box specified in the Vagrantfile and starts the VM. I don't want to start the VM, I only want to download the box.
vagrant box update downloads the box specified in the Vagrantfile, but it refuses to download a box if no versions of that box have been downloaded yet.
vagrant box add does not download the box specified in the Vagrantfile; it requires an argument. I'm trying to run this in an automated environment where the box names and/or URLs aren't known beforehand.
How can I automatically download the box in my Vagrantfile without doing anything else?
You could automate the 'vagrant up', which would download the box and then launch the virtualbox.
Then also automate
vagrant halt
vagrant destroy
Leaving you with the downloaded box ready for future 'vagrant up' usage.

Upgrade php to 5.6 in Vagrant provisioning

I upgraded php to 5.6 within the Vagrant box 'trusty64', and also installed SOAP client. When I next update Vagrant I'm thinking it might overwrite these changes. Would I also need to change the provisioning in the vagrantfile, and if so what should I add?
When I next update Vagrant I'm thinking it might overwrite these
changes.
No, You would not loose anything if you upgrade vagrant. Once the VMs are created, vagrant will operate those VMs and upgrading vagrant will not impact the existing VM.
Basically, it works like this:
- when you run vagrant up, vagrant clone the box (which is VM files) and add the VM to VirtualBox
- after the VM have been created, vagrant "operates" (i.e. start, stop ...) the VirtualBox VM for you
Would I also need to change the provisioning in the vagrantfile
Thats necessary to change the provisioning if you plan to create more VM of this kind, or if you will destroy and recreate this VM; in this case the provisioning will run and you would need to have it updated.
and if so what should I add?
save all the commands you have run to run the upgrade and create a shell script out of it, might be the most simple option. You can also look at more advanced tool (puppet, ansible, chef .... that would do this job)

Can't get vagrant destroy to work

I just deleted a large directory that I no longer needed. Unfortunately, it had a number of vagrant instances that I neglected to halt and destroy first within it and I'm having trouble getting them to go away now.
If I run "vagrant global-status", I receive four results, all have the name "default", three use hyperv and one uses virtualbox (not sure why I have a virtualbox instance at all), all but the virtualbox is running, and all in directories that no longer exist.
I just opened up the hyper-v manager and none of these instances actually exist.
If I attempt to use "vagrant destroy" against any of the ids in the global-status output, I get the following error:
There are errors in the configuration of this machine. Please fix the following errors and try again:
vm:
* A box must be specified
If I look in the "vagrant box list" command, it yields a single named box, but I don't appear to be able to do anything with it as I'll get the same error as above when I attempt to remove it.
What can I do to 1) get rid of the last of the directories that wouldn't delete since vagrant appears to be using the files and 2) clear out these entries that shouldn't be here anymore from the vagrant global-status command?
Thanks!
To clean Vagrant's global status, use the --prune flag.
I'm not sure why you don't see the Hyper-V machines in your Hyper-V manager though.
I wound up uninstalling Vagrant and deleting the directories Vagrant was using. Then I re-installed and there were no more ghost Vagrant instances.
I managed to remove the vagrant VM entry from global-status using vagrant destroy <id> after I manually deleted the VM from "Oracle VM VirtualBox". VM was ubuntu 14.04, host was windows 10.

Force Vagrant to re-provision or download a new box on next vagrant up

If I change the provision scripts or worse yet, the base OS, is there a way to force vagrant to either re-provision or re-download the base box? I tried to change the config.vm.box and config.vm.box_url, but vagrant up still happily booted up to old box.
I know I could use vagrant destroy and then vagrant up or vagrant provision for just re-provisioning on my own machine, but I'm talking about a way that automatically force my team to re-provision / reinitialize the box (e.g. after they do a git pull and then a vagrant up have it either re-provision or reinitialize appropriately.)
vagrant box --help gives you some options.
Specifically, you can vagrant box remove <name> <provider> to remove a box, and force a re-provisioning.
For example, to remove the Vagrant sample box:
vagrant box remove precise32 virtualbox

Where is Vagrant saving changes to the VM?

I am just starting with Vagrant and I am having a little trouble understanding a few details. I have read through the docs but still am missing a basic concept. When I want to start a Vagrant box I run:
vagrant up
This will "build the VM based on the box" I understand that the boxes are stored at ~/.vagrant.d and in fact I have packaged up my own box from a base Ubuntu box. However, when I run vagrant up and start to add files to the vm, where is the virtual hard drive for the vm stored? For example, when I run apt-get install apache2 and the root system is modified, where is this modified?
When I do a du on my current directory I do not see any changes. I also do not see any changes in the ~/.vagrant.d directory. However, I can do vagrant halt, restart my local machine and then run vagrant up again and the changes are persisted somewhere.
vagrant up also reports
[default] VM already created. Booting if its not already running...
Can someone tell me where the VM is created and where the changes are made?
Vagrant imports the base box which is located at ~/.vagrant.d/boxes/, like you said.
This is where the base boxes are kept. It uses it to start a VM from the clean state. When importing a VM, the responsibility of where to store data files and VM state is up to VirtualBox itself. This is a configurable location but typically defaults to ~/VirtualBox\ VMS for Mac OS X and Linux. In Windows the boxes are kept in %userprofile%\.vagrant.d\boxes
It is easy to find the place where they are getting created, regardless of what platform you happen to be using.
1. Start VirtualBox.
2. Go to the VM that shows as running instance.
3. Check out the Settings ->Storage.
4. You can find the path to location where VMs are created and stored in your file system.
I always change the directory that Virtualbox uses by default for VMs. Normally it is in your profile folder in Windows.
I change it to something like "D:\VHDs\VBox\" and there I found my vagrant test vm: "test01_1347456065". It was called test01, so I guess vagrant adds the numbers to keep things unique.

Resources