Application "Vagrant"

From SMW CindyKate - Main
Component 331456
Jump to: navigation, search

Content


Use Cases

Use Case "Associate a Vagrant project directory with an existing VirtualBox VM"

  1. Run VBoxManage list vms
  2. Copy the corresponding VM's id, e.g. 79241e6b-59c4-4bda-beff-ad6df318146a
  3. Create <project-directory>/.vagrant/machines/<vagrant-name>/virtualbox/id containing nothing but the copied VM id on the first line

Use Case "Move/copy a vagrant-controlled VM (environment) to a new workstation maintaining vagrant functionality"

Let's say you want to move a vagrant-controlled mymachine on workstation_A

[email protected]_A:~/mymachine$ tree
.
└── Vagrantfile

to

[email protected]_B:~/mymachine$ tree
.
└── Vagrantfile

and be able to do

[email protected]_B:~/mymachine$ vagrant up
[email protected]_B:~/mymachine$ vagrant ssh

as if mymachine had been created on workstation_B.

Step 1: Package

Package mymachine into a Vagrant box (see https://www.vagrantup.com/docs/cli/package.html)

[email protected]_A:~/mymachine$ vagrant package --output mymachine.box --vagrantfile Vagrantfile

It will take some time to pack

[email protected]_A:~/mymachine$ tree
.
├── mymachine.box   # <-- This is the file that is created.
└── Vagrantfile
Notice:

mymachine.box now includes [email protected]_A:~/mymachine/Vagrantfile

Step 2: Move/Copy

Move/copy

[email protected]_A:~/mymachine/mymachine.box

to

[email protected]_B:~/mymachine/mymachine.box

Step 3: Initialize

Run (see https://www.vagrantup.com/docs/cli/init.html)

[email protected]_B:~/mymachine$ vagrant init --minimal mymachine.box

This will create a minimal [email protected]_B:~/mymachine/Vagrantfile that looks like this

Vagrant.configure("2") do |config|
  config.vm.box = "mymachine.box"
end

Step 4: Start

Run

[email protected]_B:~/mymachine$ vagrant up --no-provision

This will start mymachine using settings found in

  1. [email protected]_B:~/mymachine/Vagrantfile
  2. the Vagrantfile included in the box (see step 1)
Notice:

You can override settings in Vagrantfile included in the box with settings specified in [email protected]_B:~/mymachine/Vagrantfile.

See https://www.vagrantup.com/docs/vagrantfile/#load-order.

Notice:
  • In case the Vagrantfile included in the box (see step 1) specifies e.g. shared folders or provisioners, Vagrant will prompt you to add these resources.
  • The Vagrantfile included in the box can usually be viewed at [email protected]_B:~/.vagrant.d/boxes/mymachine.box/0/virtualbox/include/_Vagrantfile.

Troubleshooting

In case you get

==> default: Machine booted and ready!
[default] GuestAdditions versions on your host (5.0.26) and guest (5.0.18) do not match.
...
The following packages will be upgraded:
 dkms
...
E: Archives directory /vagrant/cache/apt/partial is missing. - Acquire (2: No such file or directory)

try this

[email protected]:~/mediawiki-vagrant$ vagrant ssh
[email protected]:~$ mkdir -p /vagrant/cache/apt/partial
[email protected]:~$ exit
[email protected]:~/mediawiki-vagrant$ vagrant halt && vagrant up