diff options
Diffstat (limited to 'Vagrant/Vagrantfile')
-rw-r--r-- | Vagrant/Vagrantfile | 228 |
1 files changed, 228 insertions, 0 deletions
diff --git a/Vagrant/Vagrantfile b/Vagrant/Vagrantfile new file mode 100644 index 0000000..bca5718 --- /dev/null +++ b/Vagrant/Vagrantfile | |||
@@ -0,0 +1,228 @@ | |||
1 | # -*- mode: ruby -*- | ||
2 | # vi: set ft=ruby : | ||
3 | |||
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 | ||
7 | # you're doing. | ||
8 | |||
9 | # ---- Define number of nodes to spin up ---- | ||
10 | N = 3 | ||
11 | |||
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. | ||
19 | nodes = [ | ||
20 | { | ||
21 | :node => "node0", | ||
22 | :box => "mrlesmithjr/trusty64", | ||
23 | :cpu => 1, | ||
24 | :mem => 1024 | ||
25 | } | ||
26 | ] | ||
27 | |||
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 | ||
44 | ansible_groups = { | ||
45 | "test-nodes" => ["node[0:#{N-1}]"] | ||
46 | } | ||
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) | ||
53 | desktop = 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) | ||
59 | linked_clones = false | ||
60 | port_forwards = [ | ||
61 | { | ||
62 | :node => "node0", | ||
63 | :guest => 3306, | ||
64 | :host => 3306 | ||
65 | }, | ||
66 | { | ||
67 | :node => "node0", | ||
68 | :guest => 80, | ||
69 | :host => 8080 | ||
70 | }, | ||
71 | { | ||
72 | :node => "node0", | ||
73 | :guest => 8000, | ||
74 | :host => 8000 | ||
75 | } | ||
76 | ] | ||
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) | ||
80 | random_ips = false | ||
81 | #Define number of CPU cores | ||
82 | #will be ignored if custom_cpu_mem == true | ||
83 | server_cpus = 1 | ||
84 | #Define amount of memory to assign to node(s) | ||
85 | #will be ignored if custom_cpu_mem == true | ||
86 | server_memory = 512 | ||
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) | ||
90 | subnet_ip_start = 200 | ||
91 | |||
92 | Vagrant.configure(2) do |config| | ||
93 | |||
94 | #Iterate over nodes | ||
95 | (1..N).each do |node_id| | ||
96 | nid = (node_id - 1) | ||
97 | |||
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 | ||
101 | box_set = "no" | ||
102 | nodes.each do |cust_box| | ||
103 | if cust_box[:node] == "node#{nid}" | ||
104 | node.vm.box = cust_box[:box] | ||
105 | box_set = "yes" | ||
106 | end | ||
107 | end | ||
108 | if box_set == "no" | ||
109 | node.vm.box = box | ||
110 | end | ||
111 | end | ||
112 | if not enable_custom_boxes | ||
113 | node.vm.box = box | ||
114 | end | ||
115 | node.vm.provider "virtualbox" do |vb| | ||
116 | if linked_clones | ||
117 | vb.linked_clone = true | ||
118 | end | ||
119 | if not custom_cpu_mem | ||
120 | vb.customize ["modifyvm", :id, "--cpus", server_cpus] | ||
121 | vb.customize ["modifyvm", :id, "--memory", server_memory] | ||
122 | end | ||
123 | if custom_cpu_mem | ||
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]] | ||
128 | end | ||
129 | end | ||
130 | end | ||
131 | |||
132 | # Setup desktop environment | ||
133 | if desktop | ||
134 | vb.gui = true | ||
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"] | ||
140 | end | ||
141 | |||
142 | # Add additional disks | ||
143 | if 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] | ||
150 | end | ||
151 | vb.customize ['storageattach', :id, '--storagectl', \ | ||
152 | "#{additional_disks_controller}", '--port', dnum, '--device', 0, \ | ||
153 | '--type', 'hdd', '--medium', "node#{nid}_Disk#{dnum}.vdi"] | ||
154 | end | ||
155 | end | ||
156 | end | ||
157 | node.vm.hostname = "node#{nid}" | ||
158 | |||
159 | # Define additional network adapters below | ||
160 | if additional_nics | ||
161 | if not additional_nics_dhcp | ||
162 | (1..additional_nics_num).each do |nic_num| | ||
163 | if random_ips | ||
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}" | ||
168 | end | ||
169 | if not additional_nics_auto_config | ||
170 | node.vm.network :private_network, \ | ||
171 | ip: subnet+"#{subnet_ip_start + nid + nnum}", | ||
172 | auto_config: false | ||
173 | end | ||
174 | end | ||
175 | if not random_ips | ||
176 | if additional_nics_auto_config | ||
177 | node.vm.network :private_network, \ | ||
178 | ip: subnet+"#{subnet_ip_start + nid}" | ||
179 | end | ||
180 | if not additional_nics_auto_config | ||
181 | node.vm.network :private_network, \ | ||
182 | ip: subnet+"#{subnet_ip_start + nid}", | ||
183 | auto_config: false | ||
184 | end | ||
185 | end | ||
186 | end | ||
187 | end | ||
188 | if additional_nics_dhcp | ||
189 | (1..additional_nics_num).each do |nic_num| | ||
190 | node.vm.network :private_network, type: "dhcp" | ||
191 | end | ||
192 | end | ||
193 | end | ||
194 | |||
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], \ | ||
200 | host: pf[:host] | ||
201 | end | ||
202 | end | ||
203 | end | ||
204 | |||
205 | # Provisioners | ||
206 | if provision_nodes | ||
207 | if node_id == N | ||
208 | node.vm.provision "ansible" do |ansible| | ||
209 | ansible.limit = "all" | ||
210 | #runs bootstrap Ansible playbook | ||
211 | ansible.playbook = "bootstrap.yml" | ||
212 | end | ||
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 | ||
218 | end | ||
219 | end | ||
220 | end | ||
221 | |||
222 | end | ||
223 | end | ||
224 | if provision_nodes | ||
225 | #runs initial shell script | ||
226 | config.vm.provision :shell, path: "bootstrap.sh", keep_color: "true" | ||
227 | end | ||
228 | end | ||