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' :private_network, ip: ''
    node.hostmanager.aliases = %w(example-box.localdomain example-box-alias)

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 example-box-hostname example-box.localdomain example-box-alias
## vagrant-hostmanager-end

Continuous S.A.
3 avenue du Blues,
L-4368, Belvaux


© Continuous S.A. 2017