vagrant-hostmanager icon indicating copy to clipboard operation
vagrant-hostmanager copied to clipboard

vagrant-hostmanager support for multi-machine Vagrantfile?

Open rameshdharan opened this issue 8 years ago • 4 comments

Wondering if it’s possible to make vagrant-hostmanager play nicely with a multi-machine config, i.e. something like the form:

Vagrant.configure('2') do |config|
  config.vm.define "default", primary: true do |default|
     default.vm.hostname = "foo"
     default.hostmanager.enabled = true
     default.hostmanager.manage_host = true
     default.hostmanager.aliases = "bar"
     ...
  end

  config.vm.define "alternate", autostart: false do |alternate|
     alternate.vm.hostname = "foo"
     alternate.hostmanager.enabled = true
     alternate.hostmanager.manage_host = true
     alternate.hostmanager.aliases = "bar"
     ...
  end

I've tried the above with vagrant 1.7.4 and hostmanager 1.6.1 and found that the /etc/hosts entries are clobbering each other and not correct. Wondering if this is just because I'm doing it wrong, or if this type of thing is not actually supported?

rameshdharan avatar Mar 03 '16 19:03 rameshdharan

@rameshdharan shouldn't your configuration instead be

Vagrant.configure('2') do |config|
  config.hostmanager.enabled = true
  config.hostmanager.manage_host = true

  config.vm.define "default", primary: true do |default|
     default.vm.hostname = "foo"
     default.hostmanager.aliases = "fancy-name-foo"
     ...
  end

  config.vm.define "alternate", autostart: false do |alternate|
     alternate.vm.hostname = "bar"
     alternate.hostmanager.aliases = "fancy-name-bar"
     ...
  end

Does this fix it for you?

bibstha avatar Mar 10 '16 08:03 bibstha

Thx @bibstha this helped me a lot!

czerasz avatar Mar 14 '16 12:03 czerasz

@rameshdharan is there a reason why you have two machines with the same host name?

seth-reeser avatar Mar 14 '16 22:03 seth-reeser

I figured this out by trial and error and I would love someone confirm: config.hostmanager.enabled = true will work only if configured at the topmost level.

So this will work: config.hostmanager.enabled = true

And this will not: somenode.hostmanager.enabled = true

If this is the case and correct, it would be great to include in the docs, as it might save people like me hours of debugging.

Thank you.

primozcigler avatar Apr 29 '16 14:04 primozcigler