Distributing vagrant VM locally - windows

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

Related

Forgetting a VM in Vagrant

I've started a VM on Google Compute Engine using Vagrant with the vagrant-google provider. I no longer wish to control the VM using Vagrant, but I would like it to keep running without me interrupting it.
What's the proper way to have Vagrant "forget" about this machine?
so the instance has been installed on GCE and you can control directly from there.
Locally you can delete the .vagrant folder that vagrant created in the folder when you launch it
After this to remove references you can run vagrant global-status --prune which will remove invalid entries and clean vagrant conf file from this machine

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.

Ubuntu guest can't see Vagrantfile in Window's host project directory

I just installed Vagrant 1.4.3 on Windows 7 64-bit and created an Ubuntu 13.10 (Saucy) box using the following:
vagrant box add saucy64-20140226 http://cloud-images.ubuntu.com/vagrant/saucy/20140226/saucy-server-cloudimg-amd64-vagrant-disk1.box
vagrant init saucy64-20140226
After doing:
vagrant up
I SSH'ed to the vagrant box using Putty. Up to this point is fine, but when I do:
$ ls
in the /vagrant directory (on the Guest), I do not see my 'Vagrantfile' or any other files from the Host machine.
Also, any files created in the Guest's /vagrant directory do not show up in the Host's synced directory.
I noticed the following when the box/vm was starting up:
[default] The guest additions on this VM do not match the installed
version of VirtualBox! In most cases this is fine, but in rare cases
it can prevent things such as shared folders from working properly. If
you see shared folder errors, please make sure the guest additions
within the virtual machine match the version of VirtualBox you have
installed on your host and reload your VM.
After researching a little more, found that the following solves the issue:
https://github.com/dotless-de/vagrant-vbguest
Here's a more detailed post:
http://kvz.io/blog/2013/01/16/vagrant-tip-keep-virtualbox-guest-additions-in-sync/
Thanks very much to the folks who created the 'vagrant-vbguest' Vagrant plugin!!!

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