What is the Vagrant syntax for adding a locally existing VDI? - vagrant

What is the syntax for adding a locally existing VirtualBox .vdi to vagrant?
There doesn't appear to be an example of alternate URI schemes in the documentation.
Can it also use ssh and httpauth locations?

You cannot directly "import" a VirtualBox VM into Vagrant.
Basically you'll have to package the existing VirtualBox VM to a box and then add it to vagrant.
NOTE: a box is tarred VirtualBox Exports (could be gzipped).
You would be doing
Package the existing VirtualBox VM (VDI format)
vagrant package --base mybox --output /path/to/mybox.box
See more here => http://docs.vagrantup.com/v2/cli/package.html
Add the box to vagrant
vagrant box add mybox /path/to/mybox.box

Related

How to remove cached non-existing Virtualbox machines, using Hyper-V as provider?

I was using Vagrant under Windows 10 Pro first with Virtualbox provider and created a few boxes. Then because I wanted to test Docker for Win, I had to switch to Hyper V and uninstall Virtualbox. After some time I manually deleted some Virtualbox machines or re-purposed the folders so they don't have Vagrantfile anymore in them.
When I try to run either
vagrant global-status --prune
or
vagrant destroy -f XXXYYYZZZ
I get this error:
The provider 'virtualbox' that was requested to back the machine 'default' is reporting that it isn't usable on this system. The reason is shown below:
Vagrant could not detect VirtualBox! Make sure VirtualBox is properly installed. Vagrant uses the VBoxManage binary that ships with VirtualBox, and requires this to be available on the PATH. If VirtualBox is installed, please find the VBoxManage binary and add it to the PATH environmental variable.
I understand what Vagrant is trying to say: Install virtualbox binary so it can manage the boxes. But actually there are no VMs to begin with so it should be enough to delete it from registry and for that no Virtualbox is necessary. Is there a way how to remove cached boxes from registry in my case?
vagrant is keeping the list of machines it manages under the following location (that is for Mac, you would need to find for windows as I am not fully sure about the path)
~/.vagrant.d/data/machine-index
and under this folder, you'll find a index file that will list all machines it has in cache. its a JSon file and the provider for the machine is listed so you can remove anything that is not VirtualBox
I got the similar situation when I try to install Docker on my Windows 10 machine with vagrant + virtual box.
I have uninstalled virtual box, but the same error continues every time I try to run "vagrant up"
The provider 'virtualbox' that was requested to back the machine
'default' is reporting that it isn't usable on this system. The reason
is shown below:
Vagrant could not detect VirtualBox! Make sure VirtualBox is properly
installed. Vagrant uses the VBoxManage binary that ships with
VirtualBox, and requires this to be available on the PATH. If
VirtualBox is installed, please find the VBoxManage binary and add
it to the PATH environmental variable.
So below process saved me from it.
step 1: Add below line in vagrantfile below line "config.vm.box"
config.vm.define "hyperv"
Step 2: start your vagrant box calling like below from powershell or cmd
vagrant up --provider=hyperv
It should work. I got the vagrant running after these steps.
It must be the provider which is saved as virtual box somewhere in cache or registry.enter code here
source: https://willmurphyscode.net/2017/01/16/a-very-simple-vagrant-deployment/

How do I package a vagrantfile so that it is used when 'vagrant init' is called on the box?

I know this is a stupid question, I'm still struggling to grok vagrant.
I run vagrant on a windows host, and I'm building Linux guest VMs using VirtualBox. My guest VM is running, and now I want to package it.
The Vagrant documentation says "A common misconception is that the --vagrantfile option will package a Vagrantfile that is used when vagrant init is used with this box. This is not the case. Instead, a Vagrantfile is loaded and read as part of the Vagrant load process when the box is used. For more information, read about the Vagrantfile load order."
Got it. But that's what I want to do! When I run "vagrant package --output myboxname.box", my carefully-crafted Vagrant file does not appear to be in the package. I test the box as follows (in Windows, after copying the new box):
cd \some_new_dir
vagrant box add myboxname.box --name boxname
vagrant init boxname
The new Vagrantfile is the generic vagrant version, with none of my changes.
When I
vagrant up
The vm comes up fine, but (not surprisingly) none of Vagrantfile directives have happened.
I know I'm missing something basic -- can someone please help me out?
Try copying the Vagrantfile from the directory you ran vagrant package in to the \some_new_dir directory. Then, without running vagrant init (because this will overwrite the Vagrantfile with an empty file), run vagrant up to use the Vagrantfile.

Distributing vagrant VM locally

I have set up a vagrant vm on my machine. (Virtualbox)
I would like to be able to share this VM amongst other machines however would like to avoid having to download the image repeatedly.
I tried Exporting the Appliance and copying the Vagrantfile folder onto a different machine, however when i tried to connect using vagrant ssh it could not find it. I assume this is because of non-matching UUID's. How can I go around this?
Vagrant version 1.6.3
The solution was to use Vagrant Package
vagrant package --base <Name Of VM on virtualbox>
This creates a package.box file in your current directory.
You then share that package.box file, and on the new computers you execute:
vagrant init package.box
in the directory where the Vagrantfile will be created

VirtualBox Windows VM to Vagrant Base Box

I have created a Windows 8 VM in VirtualBox, and have customized settings, and installed software on it.
Now I would like to turn it into a Vagrant Base Box, so that I can share with team, and also spawn many other VMs based on my cutomized windows.
It is possible to do, I have seen Windows Base boxes in vagrantcloud. Except that there is no documentation on packaging an existing windows virtualbox VM.
Please help me with instructions, or link to instructions to create a Vagrant Base Box from my existing windows VM. creating a base box documentation does not help me, as it is for linux.
Thank you in advance SO community!
You can probably do that by using the --base argument to vagrant package.
First, locate the name of the VM on VirtualBox's GUI. Say it's called "Windows", you issue:
vagrant package --base Windows --output /path/to/windows.box
That .box file will be your base box. You can install it locally by using
vagrant box install /path/to/windows.box
Alternatively you can make it available on a server and put its URL on the config.box_url parameter in your Vagrantfile.

Vagrant package new box (from standard one)

I've got a standard Vagrant precise64 box. I want to add a number of packages, say git and subversion and then repackage the box. How can I use the package command to create a new box?
I know package is a plugin in v2. This doc was remove in v2 and I'm not sure how it applies
http://docs-v1.vagrantup.com/v1/docs/base_boxes.html
If I try in my directory containing the vagrant machine and the Vagrant file I get:
$ vagrant package boxname --output test.box --vagrantfile Vagrantfile
The machine with the name 'boxname' was not found configured for
this Vagrant environment.
Edit:
The following works
$ vagrant package --output vagrant_example.box
Which leaves me with the following questions. What is the boxname for? What does the base command do? Thanks.
I've hand crafted a couple of Vagrant base boxes (as well as using Veewee). AFAIR, the command format hasn't changed since 1.0.x.
In your case, you may have to init and up the box first, do your job and then re-package it. So the boxname (--base NAME) is the name in VirtualBox, you can get the name by using VBoxManage list vms.
vagrant package --output vagrant_example.box works because it is packaging the current vagrant box (you are in the directory where the Vagrantfile resides).
See the docs http://docs.vagrantup.com/v2/cli/package.html
--base NAME - Instead of packaging a VirtualBox machine that Vagrant manages, this will package a VirtualBox machine that VirtualBox manages. NAME should be the name or UUID of the machine from the VirtualBox GUI.

Resources