mirror of
https://codeberg.org/scottslowe/learning-tools.git
synced 2026-03-11 09:04:37 +00:00
Move contents into new folder structure based on primary technology Signed-off-by: Scott Lowe <scott.lowe@scottlowe.org>
77 lines
2.7 KiB
Ruby
77 lines
2.7 KiB
Ruby
# -*- mode: ruby -*-
|
|
# vi: set ft=ruby :
|
|
|
|
# Specify minimum Vagrant version and Vagrant API version
|
|
Vagrant.require_version '>= 1.6.0'
|
|
VAGRANTFILE_API_VERSION = '2'
|
|
|
|
# Require 'yaml' and 'erb' modules
|
|
require 'yaml'
|
|
require 'erb'
|
|
|
|
# Read YAML file with VM details (box, CPU, RAM, IP addresses)
|
|
# Be sure to edit machines.yml to provide correct IP addresses
|
|
machines = YAML.load_file(File.join(File.dirname(__FILE__), 'machines.yml'))
|
|
|
|
# Use config from YAML file to write out templates for etcd overrides
|
|
template = File.join(File.dirname(__FILE__), 'etcd.defaults.erb')
|
|
content = ERB.new File.new(template).read
|
|
|
|
etcd_initial_cluster = []
|
|
machines.each do |machine|
|
|
etcd_initial_cluster << "#{machine['name']}=http://#{machine['priv_ip']}:2380"
|
|
end
|
|
machines.each do |machine|
|
|
ip = machine['priv_ip']
|
|
target = File.join(File.dirname(__FILE__), "#{machine['name']}.defaults")
|
|
File.open(target, 'w') { |f| f.write(content.result(binding)) }
|
|
end
|
|
|
|
# Create and configure the VMs
|
|
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
|
|
|
|
# Always use Vagrant's default insecure key
|
|
config.ssh.insert_key = false
|
|
|
|
# Iterate through entries in YAML file to create VMs
|
|
machines.each do |machine|
|
|
config.vm.define machine['name'] do |srv|
|
|
|
|
# Don't check for box updates
|
|
srv.vm.box_check_update = false
|
|
|
|
# Set the hostname of the VM
|
|
srv.vm.hostname = machine['name']
|
|
|
|
# Specify the box to use (use VMware box by default)
|
|
srv.vm.box = machine['box']['vmw']
|
|
|
|
# Assign an additional static private network
|
|
srv.vm.network 'private_network', ip: machine['priv_ip']
|
|
|
|
# Specify default synced folder; requires VMware Tools
|
|
# Note shared folders are REQUIRED for the shell provisioning to work
|
|
srv.vm.synced_folder '.', '/vagrant', disabled: true
|
|
|
|
# Provision etcd to the VMs
|
|
srv.vm.provision 'file', source: 'etcd.conf',
|
|
destination: '/home/vagrant/etcd.conf'
|
|
srv.vm.provision 'file', source: "#{machine['name']}.defaults",
|
|
destination: '/home/vagrant/etcd.defaults'
|
|
srv.vm.provision 'shell', path: 'provision.sh', privileged: true
|
|
|
|
# Configure VMs with RAM and CPUs per settings in machines.yml (Fusion)
|
|
srv.vm.provider 'vmware_fusion' do |vmw|
|
|
vmw.vmx['memsize'] = machine['ram']
|
|
vmw.vmx['numvcpus'] = machine['vcpu']
|
|
end # srv.vm.provider 'vmware_fusion'
|
|
|
|
# Configure VMs with RAM and CPUs per settings in machines.yml (VirtualBox)
|
|
srv.vm.provider 'virtualbox' do |vb, override|
|
|
vb.memory = machine['ram']
|
|
vb.cpus = machine['vcpu']
|
|
override.vm.box = machine['box']['vb']
|
|
end # srv.vm.provider 'virtualbox'
|
|
end # config.vm.define
|
|
end # machines.each
|
|
end # Vagrant.configure
|