Last active
September 13, 2023 17:46
-
-
Save darkn3rd/2ce4b7321eb2cb57af434b8b37c82ece to your computer and use it in GitHub Desktop.
Vagrantfile for Dynamic MultMachine
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
# -*- 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