Skip to content

Instantly share code, notes, and snippets.

@darkn3rd
Last active September 13, 2023 17:46
Show Gist options
  • Save darkn3rd/2ce4b7321eb2cb57af434b8b37c82ece to your computer and use it in GitHub Desktop.
Save darkn3rd/2ce4b7321eb2cb57af434b8b37c82ece to your computer and use it in GitHub Desktop.
Vagrantfile for Dynamic MultMachine
# -*- mode: ruby -*-
# vi: set ft=ruby :
# default constants
TIME = Time.now.strftime('%Y%m%d%H%M%S')
CONFIGFILE_HOSTS = './config/hosts'
VAGRANT_BOX = 'bento/ubuntu-14.04'
# build hosts hash
hosts = {}
File.readlines(CONFIGFILE_HOSTS).map(&:chomp).each do |line|
ipaddr, hostname = line.split(/\s+/) # only grab first two columns
hosts[hostname] = ipaddr # store in hash
PRIMARY_SYSTEM = hostname if (line =~ /primary/) # match primary
end
Vagrant.configure('2') do |config|
hosts.each do |hostname, ipaddr|
default = if hostname == PRIMARY_SYSTEM then true else false end
config.vm.define hostname, primary: default do |node|
node.vm.box = VAGRANT_BOX
node.vm.hostname = hostname
node.vm.network 'private_network', ip: ipaddr
node.vm.provider('virtualbox') { |vbox| vbox.name = "#{hostname}_#{TIME}" }
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment