I have a bit of trouble provisioning a multi-machine setup from a Vagrantfile.
VM_NAME="node"
IMAGE_NAME="centos/7"
Nodes=3
NodeMEM=4096
NodeCPU=2
NodeGUI=false
(1..Nodes).each do |i|
Vagrant.configure("2") do |config|
v_hostname=VM_NAME+"-#{i}"
config.vm.define "node-#{i}" do |node|
node.vm.box = IMAGE_NAME
config.vm.provider "virtualbox" do |vbox|
vbox.memory = NodeMEM
vbox.cpus = NodeCPU
vbox.gui = NodeGUI
vbox.name = v_hostname
end
node.vm.hostname=v_hostname
end
end
end
My expectation: the hostname inside the VM (node.vm.hostname) and the VBox machine name are set to identical values: node-1, node-2, node-3
Actual Result: (removed some lines from network settings, guest additions and rsyncing folders)
#> vagrant up
Bringing machine 'node-1' up with 'virtualbox' provider...
Bringing machine 'node-2' up with 'virtualbox' provider...
Bringing machine 'node-3' up with 'virtualbox' provider...
==> node-1: Importing base box 'centos/7'...
==> node-1: Matching MAC address for NAT networking...
==> node-1: Checking if box 'centos/7' version '2004.01' is up to date...
==> node-1: Setting the name of the VM: node-3
==> node-1: Clearing any previously set network interfaces...
[...]
==> node-1: Setting hostname...
[...]
==> node-2: Importing base box 'centos/7'...
==> node-2: Matching MAC address for NAT networking...
==> node-2: Checking if box 'centos/7' version '2004.01' is up to date...
A VirtualBox machine with the name 'node-3' already exists.
Please use another name or delete the machine with the existing
name, and try again.
The hostname inside the VM is correctly set to "node-1" and the node name used by Vagrant as well. It's only the VBox machine name which is not set correctly.
I already tried using different orders (loop inside-out, VBox at the end), removing dashes from the hostname, setting the variables identical to v_hostname but explicitly for vbox_name.
Does anyone have an idea what's wrong here?
Additional information
I added another step to create and mount a secondary disk.
vbox.customize ["createmedium", "disk", "--filename", "/mnt/sdb/VirtualBox/disks/"+v_hostname+"-ceph.vdi", "--size", "10240"]
While the first node was still being provisioned I could see all three disks (one for each node) have alreay been created and the disk of the third node was attached to the first node.
I also tried add "--no-parallel" to "vagrant up" but no luck. I'm not sure why the "vbox.customize" steps are run for all iterations already in the first loop but I think this is the problem here.