Vagrant

Vagrant is supposed to be an easy way of running applications in preconfigured, known-to-work environments, cross-platform.

https://www.vagrantup.com/docs/getting-started/ suggests that if you're starting from something common, such as Debian Stable, then only four simple steps are needed to get your first Vagrant instance up and running:

  1. install VirtualBox
  2. run the command vagrant init hashicorp/precise64
  3. run the command vagrant up

Simple, eh?

If only…

Here is what actually happens:

0. Check that we're running Debian Stable on a 64-bit machine:

antony@vagrant:~$ cat /etc/debian_version 
8.7
antony@vagrant:~$ uname -a
Linux vagrant 3.16.0-4-amd64 #1 SMP Debian 3.16.39-1 (2016-12-30) x86_64 GNU/Linux

1. Check that virtualbox has been installed:

antony@vagrant:~$ aptitude show virtualbox
Package: virtualbox                      
State: installed
Automatically installed: no
Version: 4.3.36-dfsg-1+deb8u1

2. Install Vagrant:

root@vagrant:~# wget -nv https://releases.hashicorp.com/vagrant/1.9.1/vagrant_1.9.1_x86_64.deb
2017-02-15 20:02:03 URL:https://releases.hashicorp.com/vagrant/1.9.1/vagrant_1.9.1_x86_64.deb [87330298/87330298] -> "vagrant_1.9.1_x86_64.deb" [1]

root@vagrant:~# dpkg -i vagrant_1.9.1_x86_64.deb 
Selecting previously unselected package vagrant.
(Reading database ... 47648 files and directories currently installed.)
Preparing to unpack vagrant_1.9.1_x86_64.deb ...
Unpacking vagrant (1:1.9.1) ...
Setting up vagrant (1:1.9.1) ...
root@vagrant:~# 

3 & 4. Type the two magic commands (note that I've used precise32 here instead of the 64-bit version in the documentation because I was advised on the Vagrant mailing list to start with a 32-bit instance instead, and as far as I'm concerned, this is a 64-bit machine, so both should work, and I don't care which example I get started with):

antony@vagrant:~$ vagrant init hashicorp/precise32
A `Vagrantfile` has been placed in this directory. You are now
ready to `vagrant up` your first virtual environment! Please read
the comments in the Vagrantfile as well as documentation on
`vagrantup.com` for more information on using Vagrant.

antony@vagrant:~$ vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Box 'hashicorp/precise32' could not be found. Attempting to find and install...
    default: Box Provider: virtualbox
    default: Box Version: >= 0
==> default: Loading metadata for box 'hashicorp/precise32'
    default: URL: https://atlas.hashicorp.com/hashicorp/precise32
==> default: Adding box 'hashicorp/precise32' (v1.0.0) for provider: virtualbox
    default: Downloading: https://atlas.hashicorp.com/hashicorp/boxes/precise32/versions/1.0.0/providers/virtualbox.box
==> default: Successfully added box 'hashicorp/precise32' (v1.0.0) for 'virtualbox'!
==> default: Importing base box 'hashicorp/precise32'...
==> default: Matching MAC address for NAT networking...
==> default: Checking if box 'hashicorp/precise32' is up to date...
==> default: Setting the name of the VM: antony_default_1487190611168_5583
==> default: Clearing any previously set network interfaces...
==> default: Preparing network interfaces based on configuration...
    default: Adapter 1: nat
==> default: Forwarding ports...
    default: 22 (guest) => 2222 (host) (adapter 1)
==> default: Booting VM...
==> default: Waiting for machine to boot. This may take a few minutes...
    default: SSH address: 127.0.0.1:2222
    default: SSH username: vagrant
    default: SSH auth method: private key

long pause …

Timed out while waiting for the machine to boot. This means that
Vagrant was unable to communicate with the guest machine within
the configured ("config.vm.boot_timeout" value) time period.

If you look above, you should be able to see the error(s) that
Vagrant had when attempting to connect to the machine. These errors
are usually good hints as to what may be wrong.

If you're using a custom box, make sure that networking is properly
working and you're able to connect to the machine. It is a common
problem that networking isn't setup properly in these boxes.
Verify that authentication configurations are also setup properly,
as well.

If the box appears to be booting properly, you may want to increase
the timeout ("config.vm.boot_timeout") value.
antony@vagrant:~$ 

So, it's not as simple as https://www.vagrantup.com/docs/getting-started/ would have you believe, and nor can I find anything in that documentation about how to find out what's wrong :(

I really dislike documentation which just assumes that everything works as expected, and doesn't allow for the fact that in the real world, sometimes it doesn't.

If I look at running processes, I can see that VirtualBox appears to be doing something:

20513 ?        S      0:04 /usr/lib/virtualbox/VBoxXPCOMIPCD
20518 ?        Sl     0:20 /usr/lib/virtualbox/VBoxSVC --auto-shutdown
20894 ?        Sl     0:07 /usr/lib/virtualbox/VBoxHeadless --comment antony_default_1487190611168_5583 --startvm 7a59ec6e-becf-4bf1-a1c1-0b8d191c7733 --vrde config

Never previously having wanted or needed to interact with VirtualBox, however, I can't tell if this is what's supposed to be happening or not.

Looking at the network sockets, it appears that VirtualBox is indeed listening on port 2222 as expected:

root@vagrant:/home/antony# netstat -lptn
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp        0      0 127.0.0.1:2222          0.0.0.0:*               LISTEN      20894/VBoxHeadless

However, it doesn't do anything useful with a connection:

antony@vagrant:~$ ssh localhost -p 2222
ssh_exchange_identification: read: Connection reset by peer

antony@vagrant:~$ vagrant ssh
ssh_exchange_identification: read: Connection reset by peer

(Both the above commands involve a long delay before giving up.)


Go up
Return to main index.