Skip to content

Instantly share code, notes, and snippets.

@xinity
Created December 24, 2017 12:14
Show Gist options
  • Save xinity/5c6968e304cb1a011366fa5f6b578416 to your computer and use it in GitHub Desktop.
Save xinity/5c6968e304cb1a011366fa5f6b578416 to your computer and use it in GitHub Desktop.
vagrant multiple disk bogus
# -*- mode: ruby -*-
# vi: set ft=ruby :
# All Vagrant configuration is done below. The "2" in Vagrant.configure
# configures the configuration version (we support older styles for
# backwards compatibility). Please don't change it unless you know what
# you're doing.
Vagrant.configure(2) do |config|
config.landrush.enabled = true
config.landrush.tld = 'docker.vm'
# Application Worker Node
config.vm.define "workernode01" do |workernode01|
workernode01.vm.box = "ubuntu/xenial64"
workernode01.vm.network :private_network, ip: "192.168.3.12"
workernode01.vm.hostname = "worker01.docker.vm"
config.vm.provider :virtualbox do |vb|
vb.name = "workernode01"
line = `VBoxManage list systemproperties | grep "Default machine folder"`
vb_machine_folder = line.split(':')[1].strip()
second_diskn1 = File.join(vb_machine_folder, vb.name, 'node-ds.vmdk')
vb.customize ["modifyvm", :id, "--memory", "2048"]
vb.customize ["modifyvm", :id, "--cpus", "2"]
vb.customize ["modifyvm", :id, "--natdnsproxy1", "on"]
vb.customize ["modifyvm", :id, "--natdnshostresolver1", "on"]
vb.customize ['createhd', '--filename', second_diskn1, '--size', 10 * 1024]
vb.customize ['storageattach', :id, '--storagectl', 'SCSI', '--port', 3, '--device', 0, '--type', 'hdd', '--medium', second_diskn1 ]
end
end
# Application Worker Node
config.vm.define "workernode02" do |workernode02|
workernode02.vm.box = "ubuntu/xenial64"
workernode02.vm.network :private_network, ip: "192.168.3.13"
workernode02.vm.hostname = "worker02.docker.vm"
config.vm.provider :virtualbox do |vb2|
vb2.name = "workernode02"
line = `VBoxManage list systemproperties | grep "Default machine folder"`
vb2_machine_folder = line.split(':')[1].strip()
second_diskn2 = File.join(vb2_machine_folder, vb2.name, 'node-ds.vmdk')
vb2.customize ["modifyvm", :id, "--memory", "2048"]
vb2.customize ["modifyvm", :id, "--cpus", "2"]
vb2.customize ["modifyvm", :id, "--natdnsproxy1", "on"]
vb2.customize ["modifyvm", :id, "--natdnshostresolver1", "on"]
vb2.customize ['createhd', '--filename', second_diskn2, '--size', 10 * 1024]
vb2.customize ['storageattach', :id, '--storagectl', 'SCSI', '--port', 3, '--device', 0, '--type', 'hdd', '--medium', second_diskn2 ]
end
end
# Application Worker Node
config.vm.define "workernode03" do |workernode03|
workernode03.vm.box = "ubuntu/xenial64"
workernode03.vm.network :private_network, ip: "192.168.3.14"
workernode03.vm.hostname = "worker03.docker.vm"
config.vm.provider :virtualbox do |vb3|
vb3.name = "workernode03"
line = `VBoxManage list systemproperties | grep "Default machine folder"`
vb_machine_folder = line.split(':')[1].strip()
second_diskn3 = File.join(vb_machine_folder, vb3.name, 'node-ds.vmdk')
vb3.customize ["modifyvm", :id, "--memory", "2048"]
vb3.customize ["modifyvm", :id, "--cpus", "2"]
vb3.customize ["modifyvm", :id, "--natdnsproxy1", "on"]
vb3.customize ["modifyvm", :id, "--natdnshostresolver1", "on"]
vb3.customize ['createhd', '--filename', second_diskn3, '--size', 10 * 1024]
vb3.customize ['storageattach', :id, '--storagectl', 'SCSI', '--port', 3, '--device', 0, '--type', 'hdd', '--medium', second_diskn3 ]
end
end
# Application Worker Node
config.vm.define "workernode04" do |workernode04|
workernode04.vm.box = "ubuntu/xenial64"
workernode04.vm.network :private_network, ip: "192.168.3.15"
workernode04.vm.hostname = "worker04.docker.vm"
config.vm.provider :virtualbox do |vb4|
vb4.name = "workernode04"
line = `VBoxManage list systemproperties | grep "Default machine folder"`
vb_machine_folder = line.split(':')[1].strip()
second_diskn4 = File.join(vb_machine_folder, vb4.name, 'node-ds.vmdk')
vb4.customize ["modifyvm", :id, "--memory", "2048"]
vb4.customize ["modifyvm", :id, "--cpus", "2"]
vb4.customize ["modifyvm", :id, "--natdnsproxy1", "on"]
vb4.customize ["modifyvm", :id, "--natdnshostresolver1", "on"]
vb4.customize ['createhd', '--filename', second_diskn4, '--size', 10 * 1024]
vb4.customize ['storageattach', :id, '--storagectl', 'SCSI', '--port', 3, '--device', 0, '--type', 'hdd', '--medium', second_diskn4 ]
end
end
end
@dduportal
Copy link

dduportal commented Dec 24, 2017

WORKLOG: first launch errors on:

vagrant up
Bringing machine 'workernode01' up with 'virtualbox' provider...
Bringing machine 'workernode02' up with 'virtualbox' provider...
Bringing machine 'workernode03' up with 'virtualbox' provider...
Bringing machine 'workernode04' up with 'virtualbox' provider...
==> workernode01: Checking if box 'ubuntu/xenial64' is up to date...
==> workernode01: Machine already provisioned. Run `vagrant provision` or use the `--provision`
==> workernode01: flag to force provisioning. Provisioners marked to run always will still run.
==> workernode02: Checking if box 'ubuntu/xenial64' is up to date...
==> workernode02: Clearing any previously set forwarded ports...
==> workernode02: Fixed port collision for 22 => 2222. Now on port 2200.
==> workernode02: Clearing any previously set network interfaces...
==> workernode02: Preparing network interfaces based on configuration...
    workernode02: Adapter 1: nat
    workernode02: Adapter 2: hostonly
==> workernode02: Forwarding ports...
    workernode02: 22 (guest) => 2200 (host) (adapter 1)
==> workernode02: Running 'pre-boot' VM customizations...
A customization command failed:

["createhd", "--filename", "/Users/dadou/VirtualBox VMs/workernode01/node-ds.vmdk", "--size", 10240]

The following error was experienced:

#<Vagrant::Errors::VBoxManageError: There was an error while executing `VBoxManage`, a CLI used by Vagrant
for controlling VirtualBox. The command and stderr is shown below.

Command: ["createhd", "--filename", "/Users/dadou/VirtualBox VMs/workernode01/node-ds.vmdk", "--size", "10240"]

Stderr: 0%...
Progress state: VBOX_E_FILE_ERROR
VBoxManage: error: Failed to create medium
VBoxManage: error: Could not create the medium storage unit '/Users/dadou/VirtualBox VMs/workernode01/node-ds.vmdk'.
VBoxManage: error: VDI: cannot create image '/Users/dadou/VirtualBox VMs/workernode01/node-ds.vmdk' (VERR_ALREADY_EXISTS)
VBoxManage: error: Details: code VBOX_E_FILE_ERROR (0x80bb0004), component MediumWrap, interface IMedium
VBoxManage: error: Context: "RTEXITCODE handleCreateMedium(HandlerArg *)" at line 450 of file VBoxManageDisk.cpp
>

Please fix this customization and try again.

Proposal: fix the typo on the "config.vm.provider" where "config" has to be replaced by the VM object from the blocks "config.vm.define":

config.vm.define "workernode04" do |workernode04|
      workernode04.vm.box = "ubuntu/xenial64"
      workernode04.vm.network :private_network, ip: "192.168.3.15"
      workernode04.vm.hostname = "worker04.docker.vm"
      workernode04.vm.provider :virtualbox do |vb4|
....

@dduportal
Copy link

This Vagrantfile is starting for me:

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

# All Vagrant configuration is done below. The "2" in Vagrant.configure
# configures the configuration version (we support older styles for
# backwards compatibility). Please don't change it unless you know what
# you're doing.
Vagrant.configure(2) do |config|
  if Vagrant.has_plugin?("vagrant-some-plugin")
    config.landrush.enabled = true
    config.landrush.tld = 'docker.vm'
  end

    # Application Worker Node
    config.vm.define "workernode01" do |workernode01|
      workernode01.vm.box = "ubuntu/xenial64"
      workernode01.vm.network :private_network, ip: "192.168.3.12"
      workernode01.vm.hostname = "worker01.docker.vm"
      workernode01.vm.provider :virtualbox do |vb|
         vb.name = "workernode01"
         line = `VBoxManage list systemproperties | grep "Default machine folder"`
         vb_machine_folder = line.split(':')[1].strip()
         second_diskn1 = File.join(vb_machine_folder, vb.name, 'node-ds.vmdk')
         vb.customize ["modifyvm", :id, "--memory", "2048"]
         vb.customize ["modifyvm", :id, "--cpus", "2"]
         vb.customize ["modifyvm", :id, "--natdnsproxy1", "on"]
         vb.customize ["modifyvm", :id, "--natdnshostresolver1", "on"]
         vb.customize ['createhd', '--filename', second_diskn1, '--size', 10 * 1024]
         vb.customize ['storageattach', :id, '--storagectl', 'SCSI', '--port', 3, '--device', 0, '--type', 'hdd', '--medium', second_diskn1 ]
      end
    end


    # Application Worker Node
    config.vm.define "workernode02" do |workernode02|
      workernode02.vm.box = "ubuntu/xenial64"
      workernode02.vm.network :private_network, ip: "192.168.3.13"
      workernode02.vm.hostname = "worker02.docker.vm"
      workernode02.vm.provider :virtualbox do |vb2|
         vb2.name = "workernode02"
         line = `VBoxManage list systemproperties | grep "Default machine folder"`
         vb2_machine_folder = line.split(':')[1].strip()
         second_diskn2 = File.join(vb2_machine_folder, vb2.name, 'node-ds.vmdk')
         vb2.customize ["modifyvm", :id, "--memory", "2048"]
         vb2.customize ["modifyvm", :id, "--cpus", "2"]
         vb2.customize ["modifyvm", :id, "--natdnsproxy1", "on"]
         vb2.customize ["modifyvm", :id, "--natdnshostresolver1", "on"]
         vb2.customize ['createhd', '--filename', second_diskn2, '--size', 10 * 1024]
         vb2.customize ['storageattach', :id, '--storagectl', 'SCSI', '--port', 3, '--device', 0, '--type', 'hdd', '--medium', second_diskn2 ]
      end
    end

    # Application Worker Node
    config.vm.define "workernode03" do |workernode03|
      workernode03.vm.box = "ubuntu/xenial64"
      workernode03.vm.network :private_network, ip: "192.168.3.14"
      workernode03.vm.hostname = "worker03.docker.vm"
      workernode03.vm.provider :virtualbox do |vb3|
         vb3.name = "workernode03"
         line = `VBoxManage list systemproperties | grep "Default machine folder"`
         vb_machine_folder = line.split(':')[1].strip()
         second_diskn3 = File.join(vb_machine_folder, vb3.name, 'node-ds.vmdk')
         vb3.customize ["modifyvm", :id, "--memory", "2048"]
         vb3.customize ["modifyvm", :id, "--cpus", "2"]
         vb3.customize ["modifyvm", :id, "--natdnsproxy1", "on"]
         vb3.customize ["modifyvm", :id, "--natdnshostresolver1", "on"]
         vb3.customize ['createhd', '--filename', second_diskn3, '--size', 10 * 1024]
         vb3.customize ['storageattach', :id, '--storagectl', 'SCSI', '--port', 3, '--device', 0, '--type', 'hdd', '--medium', second_diskn3 ]
      end
    end

    # Application Worker Node
    config.vm.define "workernode04" do |workernode04|
      workernode04.vm.box = "ubuntu/xenial64"
      workernode04.vm.network :private_network, ip: "192.168.3.15"
      workernode04.vm.hostname = "worker04.docker.vm"
      workernode04.vm.provider :virtualbox do |vb4|
         vb4.name = "workernode04"
         line = `VBoxManage list systemproperties | grep "Default machine folder"`
         vb_machine_folder = line.split(':')[1].strip()
         second_diskn4 = File.join(vb_machine_folder, vb4.name, 'node-ds.vmdk')
         vb4.customize ["modifyvm", :id, "--memory", "2048"]
         vb4.customize ["modifyvm", :id, "--cpus", "2"]
         vb4.customize ["modifyvm", :id, "--natdnsproxy1", "on"]
         vb4.customize ["modifyvm", :id, "--natdnshostresolver1", "on"]
         vb4.customize ['createhd', '--filename', second_diskn4, '--size', 10 * 1024]
         vb4.customize ['storageattach', :id, '--storagectl', 'SCSI', '--port', 3, '--device', 0, '--type', 'hdd', '--medium', second_diskn4 ]
      end
    end
end

@xinity
Copy link
Author

xinity commented Dec 26, 2017

perfectly working , many thanks @dduportal

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment