2 # vi: ft=ruby:et:ts=2:sts=2:sw=2
4 VAGRANTFILE_API_VERSION = 2
10 # Defaults for Configuration data.
11 # Will be overridden from the settings file
12 # and (possibly later) from commandline parameters.
24 network_opts = [ :type, :link, :flags, :hwaddr, :name, :ipv4, :ipv6 ]
26 libvirt_network_parms = {
46 #:hostname => 'gluno1',
48 #:box => 'local-fedora-rawhide-64',
49 #:box => 'purpleidea-fedora-21',
50 #:box => 'local-fedora-21.2',
53 :container_name => 'gluno1',
54 #:container_name => 'node1',
57 :box => 'local-fedora-21.2',
61 :internal_if => 'virbr1',
65 :ipv4 => '172.20.10.30',
69 # #:ipv4 => '10.111.222.201',
76 # Load the config, if it exists,
77 # possibly override with commandline args,
78 # (currently none supported yet)
79 # and then store the config.
82 projectdir = File.expand_path File.dirname(__FILE__)
83 f = File.join(projectdir, 'vagrant.yaml')
85 settings = YAML::load_file f
87 if settings[:vms].is_a?(Array)
90 puts "Loaded settings from #{f}."
93 # TODO(?): ARGV-processing
99 File.open(f, 'w') do |file|
100 file.write settings.to_yaml
102 puts "Wrote settings to #{f}."
108 defaults.keys.each do |cat|
109 next if not vm.has_key?(cat)
110 defaults[cat].keys.each do |subcat|
111 next if not vm[cat].has_key?(subcat)
112 defaults[cat][subcat].keys.each do |key|
113 if not vm[cat][subcat].has_key?(key)
114 vm[cat][subcat][key] = defaults[cat][subcat][key]
120 #if not vm[:provider][:libvirt].has_key?(:prefix)
121 # vm[:provider][:libvirt][:prefix] = default_libvirt_prefix
124 vm[:networks].each do |net|
125 net_default.keys.each do |key|
126 if not net.has_key?(key)
127 net[key] = net_default[key]
134 # compose the list of cluster internal ips
136 cluster_internal_ips = vms.map do |vm|
138 vm[:networks].each do |n|
139 if n[:link] == vm[:internal_if]
149 #print "internal ips: "
150 #print cluster_internal_ips
153 #PROVISION_SCRIPT = <<SCRIPT
154 #yum -y install make samba
158 NET_FIX_ALWAYS_SCRIPT = <<SCRIPT
161 # eth1 is not brought up automatically
162 # by 'vagrant up' of the existing vm.
163 # because eth1 is not up, glusterd can
164 # not be started and gluster volumes can
165 # not be mounted. fix it all up here until
166 # we have a correctly working environment.
172 for MOUNTPT in $MOUNTPTS
174 grep -q -s "${MOUNTPT}" /etc/fstab && {
175 # already provisioned...
176 systemctl start glusterd
177 # sleep to give glusterd some time to start up
180 mount | grep -q -s "${MOUNTPT}" && {
181 echo "${MOUNTPT} is already mounted."
183 echo "Mounting ${MOUNTPT}."
189 # not provisioned yet
190 echo "${MOUNTPT} not set up yet. Not mounting."
196 NET_FIX_INITIAL_SCRIPT = <<SCRIPT
198 # Fix dhclient running on private network IF
200 systemctl restart NetworkManager
206 CTDB_CREATE_CONF_SCRIPT = <<SCRIPT
209 BACKUP_SUFFIX=".orig.$(date +%Y%m%d-%H%M%S)"
212 mkdir -p ${RECLOCKDIR}
213 RECLOCKFILE=${RECLOCKDIR}/reclock
215 PUBLIC_ADDRESSES_FILE=/etc/ctdb/public_addresses
216 NODES_FILE=/etc/ctdb/nodes
218 FILE=/etc/sysconfig/ctdb
219 test -f ${FILE} || touch ${FILE}
220 cp -f -a ${FILE} ${FILE}${BACKUP_SUFFIX}
224 CTDB_NODES=${NODES_FILE}
225 #CTDB_PUBLIC_ADDRESSES=${PUBLIC_ADDRESSES_FILE}
226 CTDB_RECOVERY_LOCK=${RECLOCKFILE}
227 CTDB_MANAGES_SAMBA="yes"
228 CTDB_SAMBA_SKIP_SHARE_CHECK="yes"
229 #CTDB_MANAGES_WINBIND="yes"
233 SAMBA_CREATE_CONF_SCRIPT = <<SCRIPT
236 BACKUP_SUFFIX=".orig.$(date +%Y%m%d-%H%M%S)"
242 mkdir -p ${GLUSTER_VOL_MOUNT}/share1
243 chmod -R 0777 ${GLUSTER_VOL_MOUNT}/share1
245 mkdir -p ${GLUSTER_VOL_MOUNT}/share2
246 chmod -R 0777 ${GLUSTER_VOL_MOUNT}/share2
248 FILE=/etc/samba/smb.conf
249 test -f ${FILE} || touch ${FILE}
250 cp -f -a ${FILE} ${FILE}${BACKUP_SUFFIX}
255 netbios name = sambacluster
264 vfs objects = acl_xattr glusterfs
265 glusterfs:volume = ${GLUSTER_VOL}
266 kernel share modes = no
270 path = ${GLUSTER_VOL_MOUNT}/share2
271 vfs objects = acl_xattr
277 # The vagrant machine definitions
280 Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
282 config.vm.synced_folder ".", "/vagrant", disabled: true
284 #if Vagrant.has_plugin?("vagrant-cachier")
285 # config.cache.scope = :machine
286 # #config.cache.scope = :box
288 # config.cache.synced_folder_opts = {
290 # # The nolock option can be useful for an NFSv3 client that wants to avoid the
291 # # NLM sideband protocol. Without this option, apt-get might hang if it tries
292 # # to lock files needed for /var/cache/* operations. All of this can be avoided
293 # # by using NFSv4 everywhere. Please note that the tcp option is not the default.
294 # #mount_options: ['rw', 'vers=3', 'tcp', 'nolock']
298 # just let one node do the probing
301 vms.each do |machine|
302 config.vm.define machine[:hostname] do |node|
303 node.vm.box = machine[:provider][:libvirt][:box]
304 node.vm.hostname = machine[:hostname]
306 node.vm.provider :libvirt do |libvirt|
307 libvirt.default_prefix = machine[:provider][:libvirt][:prefix]
308 libvirt.memory = 1024
309 libvirt.storage :file, :size => '64M', :device => 'vdb'
310 libvirt.storage :file, :size => '10G', :device => 'vdc'
312 machine[:networks].each do |net|
313 if not net[:ipv4] == ''
314 node.vm.network :private_network, :ip => net[:ipv4]
320 node.vm.provision "selinux", type: "shell" do |s|
321 s.path = "provision/shell/sys/selinux-off.sh"
324 # There is some problem with the fedora base box:
325 # Upon first boot, ifdown eth1 fails and the dhclient
326 # keep being active. Simply bringing down and up again
327 # the interface is not sufficient. We need to restart
328 # NetworkManager in order to teach it to not feel
329 # responsible for the interface any more.
330 ###node.vm.provision "net_fix_initial", type: "shell" do |s|
331 ### s.inline = NET_FIX_INITIAL_SCRIPT
334 node.vm.provision "install", type: "shell" do |s|
335 s.path = "provision/shell/sys/install-yum.sh"
336 s.args = [ "xfsprogs",
340 "glusterfs-geo-replication",
344 "samba-vfs-glusterfs" ]
347 # There is some problem with the fedora base box:
348 # We need to up the interface on reboots.
349 # It does not come up automatically.
350 ###node.vm.provision "net_fix_always", type: "shell", run: "always" do |s|
351 ### s.inline = NET_FIX_ALWAYS_SCRIPT
352 ### s.args = [ '/gluster/gv0', '/gluster/gv1' ]
355 # multiple privisioners with same name possible?
356 node.vm.provision "xfs_0", type: "shell" do |s|
357 s.path = "provision/shell/gluster/create-brick.sh"
358 s.args = [ "vdb", "/export" ]
361 node.vm.provision "xfs_1", type: "shell" do |s|
362 s.path = "provision/shell/gluster/create-brick.sh"
363 s.args = [ "vdc", "/export" ]
366 node.vm.provision "gluster_start", type: "shell" do |s|
367 s.path = "provision/shell/gluster/gluster-start.sh"
372 node.vm.provision "gluster_probe", type: "shell" do |s|
373 s.path = "provision/shell/gluster/gluster-probe.sh"
374 s.args = cluster_internal_ips
379 node.vm.provision "gluster_wait_peers", type: "shell" do |s|
380 s.path = "provision/shell/gluster/gluster-wait-peers.sh"
381 s.args = [ cluster_internal_ips.length, 300]
384 node.vm.provision "gluster_createvol_0", type: "shell" do |s|
385 mount_points = cluster_internal_ips.map do |ip|
386 "#{ip}:/export/vdb1/brick"
388 s.path = "provision/shell/gluster/gluster-create-volume.sh"
389 s.args = [ "gv0", "3" ] + mount_points
392 node.vm.provision "gluster_mount_0", type: "shell" do |s|
393 s.path = "provision/shell/gluster/gluster-mount-volume.sh"
394 s.args = [ "gv0", "/gluster/gv0" ]
397 node.vm.provision "gluster_createvol_1", type: "shell" do |s|
398 mount_points = cluster_internal_ips.map do |ip|
399 "#{ip}:/export/vdc1/brick"
401 s.path = "provision/shell/gluster/gluster-create-volume.sh"
402 s.args = [ "gv1", "3" ] + mount_points
405 node.vm.provision "gluster_mount_1", type: "shell" do |s|
406 s.path = "provision/shell/gluster/gluster-mount-volume.sh"
407 s.args = [ "gv1", "/gluster/gv1" ]
411 # ctdb / samba config
414 node.vm.provision "ctdb_stop", type: "shell" do |s|
415 s.path = "provision/shell/ctdb/ctdb-stop.sh"
418 node.vm.provision "ctdb_create_nodes", type: "shell" do |s|
419 s.path = "provision/shell/ctdb/ctdb-create-nodes.sh"
420 s.args = cluster_internal_ips
423 #node.vm.provision "ctdb_create_pubaddrs", type: "shell" do |s|
424 # s.path = "provision/shell/ctdb/ctdb-create-pubaddrs.sh"
428 node.vm.provision "ctdb_create_conf", type: "shell" do |s|
429 s.inline = CTDB_CREATE_CONF_SCRIPT
430 s.args = [ "/gluster/gv0/ctdb" ]
433 node.vm.provision "samba_create_conf", type: "shell" do |s|
434 s.inline = SAMBA_CREATE_CONF_SCRIPT
435 s.args = [ "gv1", "/gluster/gv1" ]
438 node.vm.provision "ctdb_start", type: "shell" do |s|
439 s.path = "provision/shell/ctdb/ctdb-start.sh"