4 # All Vagrant configuration is done below. The "2" in Vagrant.configure
5 # configures the configuration version (we support older styles for
6 # backwards compatibility). Please don't change it unless you know what
9 # ---- Define number of nodes to spin up ----
12 # ---- Define any custom memory/cpu requirement ----
13 # if custom requirements are desired...ensure to set
14 # custom_cpu_mem == true otherwise set to false
15 # By default if custom requirements are defined and set below
16 # any node not defined will be configured as the default...
17 # which is 1vCPU/512mb...So if setting custom requirements
18 # only define any node which requires more than the defaults.
22 :box => "mrlesmithjr/trusty64",
28 # ---- Define variables below ----
29 #Define if additional disks should be added (true|false)
30 additional_disks = false
31 additional_disks_controller = "SATA Controller"
32 #Define the number of additional disks to add
33 additional_disks_num = 1
34 #Define disk size in GB
35 additional_disks_size = 10
36 #Define if additional network adapters should be created (true|false)
37 additional_nics = true
38 #Define if add'l network adapters are auto configured addresses (true|false)
39 additional_nics_auto_config = true
40 #Define if additional network adapters should be DHCP assigned (true|false)
41 additional_nics_dhcp = false
42 #Define the number of additional nics to add
43 additional_nics_num = 1
45 "test-nodes" => ["node[0:#{N-1}]"]
47 #Define Vagrant box to load
48 box = "ubuntu/trusty64"
49 #Define if custom cpu and memory requirements are needed (true|false)
50 #defined within nodes variable above
51 custom_cpu_mem = false
52 #Define if running desktop OS (true|false)
54 #Define if custom boxes should be used...defined in nodes var..
55 enable_custom_boxes = false
56 #Define if port forwards should be enabled (true|false)
57 enable_port_forwards = false
58 #Defines if nodes should be linked from master VM (true|false)
77 #Define if provisioners should run (true|false)
78 provision_nodes = true
79 #Define if IP's are random assigned if not DHCP (true|false)
81 #Define number of CPU cores
82 #will be ignored if custom_cpu_mem == true
84 #Define amount of memory to assign to node(s)
85 #will be ignored if custom_cpu_mem == true
87 #Define subnet for private_network (If not using DHCP)
88 subnet = "192.168.202."
89 #Define starting last octet of the subnet range to begin addresses for node(s)
92 Vagrant.configure(2) do |config|
95 (1..N).each do |node_id|
98 config.vm.define "node#{nid}" do |node|
99 if enable_custom_boxes
100 #Initially no so it can be set to yes if found in custom box defined
102 nodes.each do |cust_box|
103 if cust_box[:node] == "node#{nid}"
104 node.vm.box = cust_box[:box]
112 if not enable_custom_boxes
115 node.vm.provider "virtualbox" do |vb|
117 vb.linked_clone = true
119 if not custom_cpu_mem
120 vb.customize ["modifyvm", :id, "--cpus", server_cpus]
121 vb.customize ["modifyvm", :id, "--memory", server_memory]
124 nodes.each do |cust_node|
125 if cust_node[:node] == "node#{nid}"
126 vb.customize ["modifyvm", :id, "--cpus", cust_node[:cpu]]
127 vb.customize ["modifyvm", :id, "--memory", cust_node[:mem]]
132 # Setup desktop environment
135 vb.customize ["modifyvm", :id, "--graphicscontroller", "vboxvga"]
136 vb.customize ["modifyvm", :id, "--accelerate3d", "on"]
137 vb.customize ["modifyvm", :id, "--ioapic", "on"]
138 vb.customize ["modifyvm", :id, "--vram", "128"]
139 vb.customize ["modifyvm", :id, "--hwvirtex", "on"]
142 # Add additional disks
144 (1..additional_disks_num).each do |disk_num|
145 dnum = (disk_num + 1)
146 ddev = ("node#{nid}_Disk#{dnum}.vdi")
147 unless File.exist?("#{ddev}")
148 vb.customize ['createhd', '--filename', ("#{ddev}"), \
149 '--variant', 'Fixed', '--size', additional_disks_size * 1024]
151 vb.customize ['storageattach', :id, '--storagectl', \
152 "#{additional_disks_controller}", '--port', dnum, '--device', 0, \
153 '--type', 'hdd', '--medium', "node#{nid}_Disk#{dnum}.vdi"]
157 node.vm.hostname = "node#{nid}"
159 # Define additional network adapters below
161 if not additional_nics_dhcp
162 (1..additional_nics_num).each do |nic_num|
164 nnum = Random.rand(0..50)
165 if additional_nics_auto_config
166 node.vm.network :private_network, \
167 ip: subnet+"#{subnet_ip_start + nid + nnum}"
169 if not additional_nics_auto_config
170 node.vm.network :private_network, \
171 ip: subnet+"#{subnet_ip_start + nid + nnum}",
176 if additional_nics_auto_config
177 node.vm.network :private_network, \
178 ip: subnet+"#{subnet_ip_start + nid}"
180 if not additional_nics_auto_config
181 node.vm.network :private_network, \
182 ip: subnet+"#{subnet_ip_start + nid}",
188 if additional_nics_dhcp
189 (1..additional_nics_num).each do |nic_num|
190 node.vm.network :private_network, type: "dhcp"
195 # Define port forwards below
196 if enable_port_forwards
197 port_forwards.each do |pf|
198 if pf[:node] == "node#{nid}"
199 node.vm.network :forwarded_port, guest: pf[:guest], \
208 node.vm.provision "ansible" do |ansible|
209 ansible.limit = "all"
210 #runs bootstrap Ansible playbook
211 ansible.playbook = "bootstrap.yml"
213 node.vm.provision "ansible" do |ansible|
214 ansible.limit = "all"
215 #runs Ansible playbook for installing roles/executing tasks
216 ansible.playbook = "playbook.yml"
217 ansible.groups = ansible_groups
225 #runs initial shell script
226 config.vm.provision :shell, path: "bootstrap.sh", keep_color: "true"