Unexpected vagrant-hostmanager behavior

Using the latest version of Trellis / Bedrock, with a couple of local projects in a single development > wordpress_sites.yml file. And a folder structure like this:

  • sites
    – project 1
    – project 2
    – project 3
  • trellis

When I start with a default hosts file and run vagrant up for the first time, it provisions and adds the following to /etc/hosts:

192.168.50.5  project1.dev  # VAGRANT: 5ac72cabab01558a2bed3$

## vagrant-hostmanager-start id: 86e5b168-0c26-4cde-9947-8f47328b313b
192.168.50.5    project1.dev
192.168.50.5    project2.dev
192.168.50.5    project3.dev
192.168.50.5    www.project1.dev
192.168.50.5    www.project2.dev
192.168.50.5    www.project3.dev
## vagrant-hostmanager-end

Of all the projects only project 1 is in the first host line and added a second time in the next block with hosts along with the rest of the projects. When I halt the machine, the line:

192.168.50.5 project1.dev # VAGRANT: 5ac72cabab01558a2bed3$

is removed. But the block:

## vagrant-hostmanager-start id: 86e5b168-0c26-4cde-9947-8f47328b313b
192.168.50.5    project1.dev
192.168.50.5    project2.dev
192.168.50.5    project3.dev
192.168.50.5    www.project1.dev
192.168.50.5    www.project2.dev
192.168.50.5    www.project3.dev
## vagrant-hostmanager-end

remains.

I suspect this is not how it is supposed to work. Could this be a bug or perhaps a faulty setup on my part somewhere?

My host OS is Ubuntu 14.04.3 with kernel 3.16.0-57-generic, Virtualbox 4.3.30r101610 with Vagrant 1.7.2 and the latest vagrant-hostmanager plugin.

Let me know if I need to provide any additional info.

Greetings,
Richard

The first line is being added by vagrant-hostsupdater. The second block is being added by vagrant-hostmanager. It’s not harming anything by being in there twice, so if you need vagrant-hostsupdater for other projects, then just ignore this issue (or see if there’s a way to suppress vagrant-hostsupdater in your Vagrantfile; I’m not sure if there’s a way to do that). Otherwise you can just uninstall vagrant-hostsupdater.

Update: I went and looked it up. You can suppress it. I’ve done it here: https://github.com/roots/trellis/pull/458/files

4 Likes

Thanks for your reply! So vagrant-hostsupdater is the one Trellis uses? Has this recently changed and is the vagrant-hostmanager plugin not necessary anymore? I was wondering since the Trellis requirements still lists vagrant-hostmanager.

Also vagrant-hostsupdater only adds the first site, is it somehow possible to have it add all sites from the development > wordpress_sites.yml file?

Trellis uses vagrant-hostmanager. You can uninstall vagrant-hostsupdater if you no longer need it for any other projects. Otherwise, just add skip to your Vagrantfile like I did in that PR.

vagrant-hostmanager will add all sites in the wordpress_sites.yml.

To clarify, vagrant-hostsupdater automatically updates your hosts file for every vagrant instance, regardless of whether you explicitly configure it in your Vagrantfile. That’s what’s happening here. You can (A) ignore it; or (B) suppress (skip) it.

1 Like