-
Notifications
You must be signed in to change notification settings - Fork 6
/
Vagrantfile
77 lines (61 loc) · 2.41 KB
/
Vagrantfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# -*- mode: ruby -*-
# vi: set ft=ruby :
# Returns true if `GUI` environment variable is set to a non-empty value.
# Defaults to false
def gui_enabled?
!ENV.fetch('GUI', '').empty?
end
# optionally connect the VM to a src dir. set STACKI_SRC=/PATH/TO/SRC/
def src_enabled?
!ENV.fetch('STACKI_SRC', '').empty?
end
# stacki has some minimum requirements above what's provided by most vagrant boxes
# this includes >2gb of ram, 64GB of disk, and a dedicated non-NAT nic
# for details, see https://github.com/StackIQ/stacki/wiki/Frontend-Installation
# Adjust the VM networking based on the contents of site.attrs
mac_addr = ''
ip_addr = ''
iface = ''
# grab it from http or cwd
attrs_file = 'http/site.attrs' if File.file?('http/site.attrs')
attrs_file = 'site.attrs' if File.file?('site.attrs')
File.open(attrs_file).each_line do |line|
key, value = line.split(':', 2)
if key == "Kickstart_PrivateEthernet"
mac_addr = value.strip
elsif key == "Kickstart_PrivateAddress"
ip_addr = value.strip
elsif key == "Kickstart_PrivateInterface"
iface = value.strip
end
end
Vagrant.configure(2) do |config|
config.vm.box = "stacki/stackios"
# Add a nic for a backend install network
config.vm.network "private_network", ip: ip_addr, :mac => mac_addr.tr(':', '')
config.vm.provider "virtualbox" do |vb|
# Customize the amount of memory on the VM:
vb.memory = "3072"
# give the VM a pretty name in VBox Manager
time = Time.new
vb.name = "StackiFrontend-3.2-" + time.strftime("%Y-%m-%d-%H-%M-%S")
# Display the VirtualBox GUI when booting the machine
vb.gui = gui_enabled?
end
# if defined, connect the stacki src dir, and forward the SSH agent
if src_enabled?
config.ssh.forward_agent = true
config.vm.synced_folder ENV['STACKI_SRC'], "/export/src/"
end
# fix the VM networking to reflect what's in site.attrs
# note that we actually changed the MAC of that NIC above, so we want to match here
# and delete any references to overriding it in software ('macaddr=')
config.vm.provision "shell", env: {"iface" => iface, "new_mac" => mac_addr}, inline: <<-SHELL
ifdown ${iface}
sed -i -r "s/HWADDR=.*$/HWADDR=${new_mac}/" /etc/sysconfig/network-scripts/ifcfg-${iface}
sed -i -r "s/MACADDR=.*$/HWADDR=${new_mac}/" /etc/sysconfig/network-scripts/ifcfg-${iface}
ifup ${iface}
SHELL
# make it easy to extend
config.vm.provision "shell", path: "scripts/local.sh"
end