This repository was archived by the owner on Jan 21, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVagrantfile
183 lines (153 loc) · 5.26 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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
#
# Dev lab Vagrantfile
#
#
# Vars
#
# el8admin options:
MY_VM_RAM = "4096"
MY_VM_CPU = "4"
MY_VM_CODE = "./vm-code-admin/"
# Enable the multi-machine setup? yes/no
MULTIVM = "yes"
# Number of Node VMs to create?
NODES = 2
# el8node{i} options:
NODE_CPU = "2"
NODE_RAM = "2048"
NODE_CODE = "./vm-code-node/"
# vagrant options
VAGRANT_API_VER = "2"
VAGRANT_DISABLE_VBOXSYMLINKCREATE = 1
CODE_MNT = "/opt/code"
CODE_MNT_OPT = ["dmode=775,fmode=644"]
Vagrant.configure("2") do |config|
#
# Box and VM config
#
config.vm.box = "centos8vm"
config.ssh.username = "root"
config.ssh.insert_key = true
config.vm.synced_folder ".", "/vagrant", disabled: true
#
# Virtual machines
#
# el8admin
config.vm.define "el8admin" do |mainvm|
config.vm.hostname = "el8admin"
config.ssh.forward_agent = false
config.vm.disk :disk, size: "50GB", primary: true
# provider specific conf
# --- Windows Hyper-V ---
mainvm.vm.provider :hyperv do |hpv, override|
hpv.memory = MY_VM_RAM
hpv.maxmemory = MY_VM_RAM
hpv.cpus = MY_VM_CPU
hpv.vmname = "el8admin"
# network
config.vm.network "public_network",
bridge: "PackerSwitch"
config.vm.network "private_network",
bridge: "PackerSwitch"
# file shares
override.vm.synced_folder MY_VM_CODE, CODE_MNT,
type: "rsync",
mount_options: CODE_MNT_OPT
end
# --- Libvirt ---
config.vm.provider :libvirt do |libv, override|
# file shares
override.vm.synced_folder MY_VM_CODE, CODE_MNT,
type: "rsync",
mount_options: CODE_MNT_OPT
end
# run centos8-admin-playbook.yml
# generic ansible roles used on adminvm
mainvm.vm.provision "ansible_local" do |ansible|
ansible.groups = {
"localhost" => ["el8admin"]
}
ansible.compatibility_mode = "2.0"
ansible.config_file = "ansible_vagrant.cfg"
ansible.playbook = "centos8-admin-playbook.yml"
ansible.provisioning_path = CODE_MNT + "/ansible/"
ansible.install = false
ansible.verbose = false
end
# run centos8-admin-role.yml
# single file playbook - tasks specific to the adminvm
mainvm.vm.provision "ansible_local" do |ansible|
ansible.groups = {
"localhost" => ["el8admin"]
}
ansible.compatibility_mode = "2.0"
ansible.config_file = "ansible.cfg"
ansible.playbook = "centos8-admin-role.yml"
ansible.provisioning_path = CODE_MNT + "/ansible/"
ansible.install = false
ansible.verbose = true
end
# port forward
config.vm.network :forwarded_port,
guest: 9090, host: 9090,
auto_correct: true,
id: 'cockpit'
end
# Node machines
if MULTIVM == "yes"
# loop over nodes
(1..NODES).each do |i|
# create the VM
config.vm.define "el8node#{i}" do |node|
node.vm.hostname = "el8node#{i}"
node.vm.disk :disk, size: "2GB", name: "node_storage"
# provider specific conf
# --- Windows Hyper-V ---
node.vm.provider :hyperv do |hpv, override|
hpv.vmname = "el8node#{i}"
hpv.memory = NODE_RAM
hpv.cpus = NODE_CPU
# network
config.vm.network "public_network",
bridge: "PackerSwitch"
config.vm.network "private_network",
bridge: "PackerSwitch"
# file shares
override.vm.synced_folder NODE_CODE, CODE_MNT,
type: "rsync",
mount_options: CODE_MNT_OPT
end
# --- Libvirt ---
config.vm.provider :libvirt do |libv, override|
# file shares
override.vm.synced_folder NODE_CODE, CODE_MNT,
type: "rsync",
mount_options: CODE_MNT_OPT
end
end
end
end
#
# provision tasks (all VMs)
#
config.vm.provision :shell,
:privileged => true,
:path => "scripts/vagrant/setup.sh",
:upload_path => "/etc/centos8vm/setup.sh",
:binary => true,
name: "vagrant vm setup.sh"
config.vm.provision :shell,
:privileged => true,
:path => "scripts/vagrant/install_avahi.sh",
:upload_path => "/etc/centos8vm/install_avahi.sh",
:binary => true,
name: "vagrant vm install_avahi.sh"
config.vm.provision :shell,
:privileged => true,
:path => "scripts/test.sh",
:upload_path => "/etc/centos8vm/test.sh",
:binary => true,
name: "vagrant vm test.sh"
end
# -*- mode: ruby -*-
# vi: ft=ruby :