Skip to content

Instantly share code, notes, and snippets.

Last active September 13, 2023 17:46
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
Star You must be signed in to star a gist
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 ='%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
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| = VAGRANT_BOX
node.vm.hostname = hostname 'private_network', ip: ipaddr
node.vm.provider('virtualbox') { |vbox| = "#{hostname}_#{TIME}" }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment