adding additional network adapter to use host only network with dhcp in vagrant using virtualbox provider [closed]

here's what I am trying to achieve

  1. adapter 1 runs on usual NAT
  2. add an additional adapter using the vboxnet0 host only network I have created in virtual box, this one uses DHCP server

the reason I need dhcp server is because there is a logstash server running on vagrant box in the same host machine and all the other boxes that I bring up using vagrant should be shipping to this logstash instance, and hence I have to use the hostname logstash.agilityroots.com in each of them instead of relying on hardcoding IPs to each of them.

the Host only network and dhcp settings are on Virtualbox as follows

Anadis-MacBook-Pro:bin anadi$ VBoxManage list -l hostonlyifs
Name:            vboxnet0
GUID:            786f6276-656e-4074-8000-0a0027000000
DHCP:            Disabled
IPAddress:       192.168.10.1
NetworkMask:     255.255.255.0
IPV6Address:     
IPV6NetworkMaskPrefixLength: 0
HardwareAddress: 0a:00:27:00:00:00
MediumType:      Ethernet
Status:          Up
VBoxNetworkName: HostInterfaceNetworking-vboxnet0


Anadis-MacBook-Pro:bin anadi$ VBoxManage list -l dhcpservers
NetworkName:    HostInterfaceNetworking-vboxnet0
IP:             192.168.56.100
NetworkMask:    255.255.255.0
lowerIPAddress: 192.168.56.101
upperIPAddress: 192.168.56.254
Enabled:        Yes

here's the vagrant file

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

# Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
VAGRANTFILE_API_VERSION = "2"

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|

  config.vm.define "full-stack-env" do |dev|
      dev.vm.box = "devops-vm"
      dev.vm.hostname = "full-stack-env.agilityroots.com"

      dev.vm.synced_folder "../../shared-data/yum", "/yum"
      dev.vm.synced_folder "../../puppet-manifests/files", "/etc/puppet/files"

      # add additional adapter for inter machine networking
      dev.vm.network "private_network", type: "dhcp"
      #dev.vm.network :private_network, :type => "dhcp", :adapter => "2"

      dev.vm.network :forwarded_port, guest: 22,host: 4223, id: "ssh", auto_correct: true
      #setting port forward for tomcat
      dev.vm.network :forwarded_port, guest: 8080, host: 8090
      #setting port forward for elasticsearch
      dev.vm.network :forwarded_port, guest: 9200, host: 9200

      dev.vm.provider :virtualbox do |vbox|
        vbox.name = "full-stack-env"
      end

      dev.vm.provision :puppet do |puppet|
        puppet.options = "--verbose --fileserverconfig=/vagrant/fileserver.conf"
        puppet.module_path = "../../puppet-manifests/modules"
        puppet.manifests_path = "../../puppet-manifests/dev-env"
        puppet.manifest_file = "site.pp"
      end
  end
end

this throws the error

Anadis-MacBook-Pro:full-stack-env anadi$ vagrant up
Bringing machine 'full-stack-env' up with 'virtualbox' provider...
There are errors in the configuration of this machine. Please fix
the following errors and try again:

vm:
* An IP is required for a private network.

is there a way to get vagrant using DHCP enabled host only networking?


Solution 1:

This should have been fixed in Vagrant 1.5.2 (issue). So you could either upgrade or use a symbol:

dev.vm.network "private_network", type: :dhcp