Last active
April 28, 2018 22:22
-
-
Save TheNotary/92e89f294a807695382ac4ed0f800d8e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
storage-host-vm: | |
- | |
file: vault_1 | |
size: 1024 | |
format: ext4 | |
raid_device: true | |
hypervisor_path: /storage/blah | |
mount_path: /vault | |
- | |
file: vault_2 | |
size: 1024 | |
format: ext4 | |
raid_device: true | |
hypervisor_path: /storage/blah | |
mount_path: /vault | |
- | |
file: drv_a | |
size: 1024 | |
format: ext4 | |
hypervisor_path: /storage/blah | |
mount_path: /storage/drv_a | |
- | |
file: drv_b | |
size: 1024 | |
format: ext4 | |
hypervisor_path: /storage/blah | |
mount_path: /storage/drv_b |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'json' | |
require 'yaml' | |
# Make sure the vagrant-ignition plugin is installed | |
required_plugins = %w(vagrant-ignition) # vagrant-persistent-storage | |
plugins_to_install = required_plugins.select { |plugin| not Vagrant.has_plugin? plugin } | |
if not plugins_to_install.empty? | |
puts "Installing plugins: #{plugins_to_install.join(' ')}" | |
if system "vagrant plugin install #{plugins_to_install.join(' ')}" | |
exec "vagrant #{ARGV.join(' ')}" | |
else | |
abort "Installation of one or more plugins has failed. Aborting." | |
end | |
end | |
def sata_controller_exists?(controller_name="SATA Controller") | |
`vboxmanage showvminfo storage-host-vm-dev | grep " #{controller_name}" | wc -l`.to_i == 1 | |
end | |
def port_in_use?(controller_name, port) | |
`vboxmanage showvminfo storage-host-vm-dev | grep "SATA Controller (#{port}, " | wc -l`.to_i == 1 | |
end | |
def attach_hdd(v, controller_name, port, hdd_path) | |
unless port_in_use?(controller_name, port) | |
v.customize ['storageattach', :id, '--storagectl', 'SATA Controller', '--port', port, '--device', 0, '--type', 'hdd', '--medium', hdd_path] | |
end | |
end | |
config_data = JSON.parse( File.read("variables.json") ) | |
debian_vms = [ | |
{ name: "it-workhorse-vm", ip: "48" }, | |
{ name: "storage-host-vm", ip: "139" }, | |
{ name: "rock", ip: "54" }, | |
{ name: "backups-dark-vm", ip: "128" }, | |
{ name: "ubuntu-vm", ip: "127" }, | |
{ name: "jenkins-vm", ip: "52" } ] | |
vm_name_prefix = "virtualbox" | |
Vagrant.configure("2") do |config| | |
config.ssh.insert_key = false | |
config.ssh.private_key_path = "~/.ssh/id_rsa" | |
debian_vms.each do |vm| | |
config.vm.define "#{vm[:name]}" do |node_config| | |
node_config.vm.hostname = vm[:name] | |
node_config.vm.box = "#{vm_name_prefix}_#{vm[:name]}.box" | |
node_config.vm.box_url = "file://builds/#{vm_name_prefix}_#{vm[:name]}.box" # FIXME: Test that this even works... | |
node_config.vm.network :private_network, ip: "172.16.3.#{vm[:ip]}" | |
config.vm.synced_folder '.', '/vagrant', disabled: true | |
config.ssh.username = config_data['user_name'] | |
config.vm.provider :virtualbox do |v| | |
v.name = vm[:name] + "-dev" | |
v.gui = false | |
v.memory = 1024 # aren't these values baked into the .box file? | |
v.cpus = 1 | |
v.customize ["modifyvm", :id, "--natdnshostresolver1", "on"] | |
v.customize ["modifyvm", :id, "--ioapic", "on"] | |
strj = YAML.load_file("storage.yml") | |
if strj[vm[:name]] # attach storage to VM if defined in storage.yml | |
controller_name = 'SATA Controller' | |
v.customize ['storagectl', :id, '--name', controller_name, '--add', 'sata', '--portcount', 4] unless sata_controller_exists?(controller_name) | |
strj[vm[:name]].each_with_index do |strj_spec, i| | |
virtual_disk_path = "./packer_cache/#{vm[:name]}_#{strj_spec['file']}.vdi" | |
v.customize ['createhd', '--filename', virtual_disk_path, '--size', 1 * 1024] unless File.exist?(virtual_disk_path) | |
attach_hdd(v, controller_name, i, virtual_disk_path) | |
end | |
end | |
v.functional_vboxsf = false | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment