Version 2.0.+ of Vagrant default hosts to in /etc/hosts with docker provider

So if you have recently upgraded Vagrant like I did to a version greater than 2.0.X and you regularly use vagrant plugin vagrant-hostmanager to keep track of your host alias in both /etc/hosts in your local machine and docker containers

It’s highly likely that whenever you run

vagrant up my-favourite-machine

Results in having part of /etc/hosts looking like this

## vagrant-hostmanager-start id: 3ee2758e-bdf2-4086-b999-0ecea4a973f9	my-favourite-machine
## vagrant-hostmanager-end

When it should look similar to this:

## vagrant-hostmanager-start id: 3ee2758e-bdf2-4086-b999-0ecea4a973f9	my-favourite-machine
## vagrant-hostmanager-end

This breaks all sort of configurations that require local dns resolvers specially when linking across containers

So current solution as far as I can see, having an issue open on the github repo without answer so far is actually to downgrade Vagrant, as I’m not taking advantage of any introduction brought up by versions of Vagrant greater than 2.0+

The solution passes by the downgrade to a stabler and on previous major version.

Since we keep Vagrant versioned at 1.9.1 here at Fiercely in our Jenkins Slaves, I can confidently assure you this versions is stable and useable with vagrant-hostmanager when using a docker provider.

I’m not unable to test, as I don’t have access to VMWare, but downgrade should also fix the issue of defaulting VM’s defaulting to when using Vmware as a Vagrant Provider along with vagrant-hostmanager. (another open issue at the plugin github repo for the time being)

How to downgrade Vagrant on Linux to a different version.

First remove it according to Hashicorp’s documentation

Removing vagrant

    rm -rf /opt/vagrant
    rm -f /usr/bin/vagrant

Don’t eliminate your ~/.vagrant.d , there is no need to do it

Then let’s download version 1.9.1 (or whatever you prefer), but can confirm to fix this issue it works on version: 1.9.1

If you came just looking for How to downgrade Vagrant on Linux to a previous version than install whatever version you wish

Now let’s download and install the Vagrant version we wish

Instatling Vagrant On Debian/Ubuntu:

    export VAGRANT_VERSION=1.9.1
    wget${VAGRANT_VERSION}/vagrant_${VAGRANT_VERSION}_x86_64.deb -P /tmp
    sudo dpkg -i /tmp/vagrant_${VAGRANT_VERSION}_x86_64.deb
    #Remove Download
    rm /tmp/${VAGRANT_VERSION}/vagrant_${VAGRANT_VERSION}_x86_64.deb

Installing Vagrant On CentOS/Fedora/Redhat

    export VAGRANT_VERSION=1.9.1
    wget${VAGRANT_VERSION}/vagrant_${VAGRANT_VERSION}_x86_64.rpm -P /tmp
    sudo rpm -ivh /tmp/${VAGRANT_VERSION}/vagrant_${VAGRANT_VERSION}_x86_64.rpm
    #Remove Download
    rm /tmp/${VAGRANT_VERSION}/vagrant_${VAGRANT_VERSION}_x86_64.rpm

You now need to update the plugins

vagrant plugin update

If the above gives you any conflict, you might as well remove plugins to reinstall in case of incompatibility in versions

vagrant plugin expunge
#Answer Yes to the following questions regarding removing the plugins

Then reinstall, in this vagrant-hostmanager

vagrant plugin install vagrant-hostmanager

And now when you vagrant up favourite-machine

Both your /etc/host at local machine and VM/container should contain the correct values, and not the default ones.

The opinons on this Post are solely mine and not those of my employers

André Ilhicas dos Santos

Devops Padawan, curious about systems automation, learning new languages, paradigms tools each day.

ilhicas ilhicas