Vagrant-hostmaster

April 3rd, 2017 Posted by Blog, DevOps, Tips 0 thoughts on “Vagrant-hostmaster”

vagrant-hostmanager is a plugin that manages the hosts file on guest machines (and optionally the host). Its goal is to enable resolution of multi-machine environments deployed with a cloud provider where IP addresses are not known in advance.

Edit your Vagrantfile and add the vagrant-hostmanager configuration:

# -*- mode: ruby -*-
# vi: set ft=ruby :

BOX_NAME = "ubuntu/ubuntu1604"

Vagrant.configure("2") do |config|

  config.hostmanager.enabled = true
  config.hostmanager.manage_host = true
  config.hostmanager.manage_guest = true
  config.hostmanager.ignore_private_ip = false
  config.hostmanager.include_offline = true
  config.vm.define 'example-box' do |node|
    node.vm.hostname = 'example-box-hostname'
    node.vm.network :private_network, ip: '192.168.42.42'
    node.hostmanager.aliases = %w(example-box.localdomain example-box-alias)
  end
end

After a vagrant up, your vagrant IP is now in your /etc/hosts:

vagrant up
Bringing machine ‘example-box’ up with ‘virtualbox’ provider…
cat /etc/hosts
## vagrant-hostmanager-start id: 31fcefac-77cb-4733-afc4-43c01ac6d278
192.168.42.42 example-box-hostname
192.168.42.42 example-box.localdomain
192.168.42.42 example-box-alias
## vagrant-hostmanager-end

Continuous S.A.
Avenue des Hauts-Fourneaux 9
L-4362 Esch-sur-Alzette
Luxembourg

© Continuous S.A. 2017