forked from mrlesmithjr/python-powerdns-management
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVagrantfile
155 lines (145 loc) · 5.82 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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
# -*- mode: ruby -*-
# vi: set ft=ruby :
# All Vagrant configuration is done below. The "2" in Vagrant.configure
# configures the configuration version (we support older styles for
# backwards compatibility). Please don't change it unless you know what
# you're doing.
# ---- Define number of nodes to spin up ----
N = 3
# ---- Define any custom memory/cpu requirement ----
# if custom requirements are desired...ensure to set
# custom_cpu_mem == "yes" otherwise set to "no"
# By default if custom requirements are defined and set below
# any node not defined will be configured as the default...
# which is 1vCPU/512mb...So if setting custom requirements
# only define any node which requires more than the defaults.
nodes = [
{
:node => "node0",
:cpu => 1,
:mem => 4096
}
]
# ---- Define variables below ----
additional_disks = "no" #Define if additional drives defined should be added (yes | no)
additional_disks_controller = "SATA Controller"
additional_disks_num = 1 #Define the number of additional disks to add
additional_disks_size = 10 #Define disk size in GB
additional_nics = "yes" #Define if additional network adapters should be created (yes | no)
additional_nics_dhcp = "no" #Define if additional network adapters should be DHCP assigned
additional_nics_num = 1 #Define the number of additional nics to add
ansible_groups = {
"master-nodes" => ["node0"],
"slave-nodes" => ["node1", "node2"]
}
box = "mrlesmithjr/trusty64" #Define Vagrant box to load
custom_cpu_mem = "no" #Define if custom cpu and memory requirements are needed (yes| no)...defined within nodes variable above
desktop = "no" #Define if running desktop OS (yes | no)
enable_port_forwards = "yes" #Define if port forwards should be enabled
linked_clones = "no" #Defines if nodes should be linked from master VM (yes | no)
port_forwards = [
{
:node => "node0",
:guest => 80,
:host => 8080
},
{
:node => "node0",
:guest => 8081,
:host => 8081
}
]
provision_nodes = "yes" #Define if provisioners should run (yes | no)
random_ips = "no" #Define if IP's are random assigned if not DHCP
server_cpus = 1 #Define number of CPU cores...will be ignored if custom_cpu_mem == "yes"
server_memory = 512 #Define amount of memory to assign to node(s)...will be ignored if custom_cpu_mem == "yes"
subnet = "192.168.202." #Define subnet for private_network (If not using DHCP)
subnet_ip_start = 200 #Define starting last octet of the subnet range to begin addresses for node(s)
Vagrant.configure(2) do |config|
#Iterate over nodes
(1..N).each do |node_id|
nid = (node_id - 1)
config.vm.define "node#{nid}" do |node|
node.vm.box = box
node.vm.provider "virtualbox" do |vb|
if linked_clones == "yes"
vb.linked_clone = true
end
if custom_cpu_mem == "no"
vb.customize ["modifyvm", :id, "--cpus", server_cpus]
vb.customize ["modifyvm", :id, "--memory", server_memory]
end
if custom_cpu_mem == "yes"
nodes.each do |cust_node|
if cust_node[:node] == "node#{nid}"
vb.customize ["modifyvm", :id, "--cpus", cust_node[:cpu]]
vb.customize ["modifyvm", :id, "--memory", cust_node[:mem]]
end
end
end
if desktop == "yes"
vb.gui = true
vb.customize ["modifyvm", :id, "--graphicscontroller", "vboxvga"]
vb.customize ["modifyvm", :id, "--accelerate3d", "on"]
vb.customize ["modifyvm", :id, "--ioapic", "on"]
vb.customize ["modifyvm", :id, "--vram", "128"]
vb.customize ["modifyvm", :id, "--hwvirtex", "on"]
end
if additional_disks == "yes"
(1..additional_disks_num).each do |disk_num|
dnum = (disk_num + 1)
ddev = ("node#{nid}_Disk#{dnum}.vdi")
unless File.exist?("#{ddev}")
vb.customize ['createhd', '--filename', ("#{ddev}"), '--variant', 'Fixed', '--size', additional_disks_size * 1024]
end
vb.customize ['storageattach', :id, '--storagectl', "#{additional_disks_controller}", '--port', dnum, '--device', 0, '--type', 'hdd', '--medium', "node#{nid}_Disk#{dnum}.vdi"]
end
end
end
node.vm.hostname = "node#{nid}"
### Define additional network adapters below
if additional_nics == "yes"
if additional_nics_dhcp == "no"
(1..additional_nics_num).each do |nic_num|
if random_ips == "yes"
nnum = Random.rand(0..50)
node.vm.network :private_network, ip: subnet+"#{subnet_ip_start + nid + nnum}"
end
if random_ips == "no"
node.vm.network :private_network, ip: subnet+"#{subnet_ip_start + nid}"
end
end
end
if additional_nics_dhcp == "yes"
(1..additional_nics_num).each do |nic_num|
node.vm.network :private_network, type: "dhcp"
end
end
end
### Define port forwards below
if enable_port_forwards == "yes"
port_forwards.each do |pf|
if pf[:node] == "node#{nid}"
node.vm.network "forwarded_port", guest: pf[:guest], host: pf[:host] + nid
end
end
end
if provision_nodes == "yes"
if node_id == N
node.vm.provision "ansible" do |ansible| #runs bootstrap Ansible playbook
ansible.limit = "all"
ansible.playbook = "bootstrap.yml"
end
node.vm.provision "ansible" do |ansible| #runs Ansible playbook for installing roles/executing tasks
ansible.limit = "all"
ansible.playbook = "playbook.yml"
ansible.groups = ansible_groups
end
end
end
end
end
if provision_nodes == "yes"
config.vm.provision :shell, path: "bootstrap.sh", keep_color: "true" #runs initial shell script
end
end