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
157 NET_FIX_ALWAYS_SCRIPT = <<SCRIPT
160 # eth1 is not brought up automatically
161 # by 'vagrant up' of the existing vm
162 # because eth1 is not up, glusterd can
163 # not be started and gluster volumes can
164 # not be mountd. fix it all up here until
165 # we have a correctly working environment
171 for MOUNTPT in $MOUNTPTS
173 grep -q -s "${MOUNTPT}" /etc/fstab && {
174 # already provisioned...
175 systemctl start glusterd
176 # sleep to give glusterd some time to start up
179 mount | grep -q -s "${MOUNTPT}" && {
180 echo "${MOUNTPT} is already mounted."
182 echo "Mounting ${MOUNTPT}."
186 # not provisioned yet
187 echo "${MOUNTPT} not set up yet. Not mounting."
193 NET_FIX_INITIAL_SCRIPT = <<SCRIPT
195 # Fix dhclient running on private network IF
197 systemctl restart NetworkManager
202 INSTALL_SCRIPT = <<SCRIPT
205 echo "Installing software..."
207 yum -y install xfsprogs
208 yum -y install glusterfs{,-server,-fuse,-geo-replication}
209 yum -y install ctdb samba
212 XFS_SCRIPT = <<SCRIPT
217 DISKDEV="/dev/${DEVICE}"
218 DISKPARTDEV="/dev/${PARTDEV}"
220 MOUNTP=/export/${PARTDEV}
221 BRICKD=${MOUNTP}/brick
223 BACKUP_SUFFIX=".orig.$(date +%Y%m%d-%H%M%S)"
225 parted -s ${DISKDEV} print > /dev/null 2>&1 && {
226 echo "Labe exists on ${DISKDEV}."
228 echo "Creating label on ${DISKDEV}."
229 parted -s ${DISKDEV} mklabel msdos
232 parted -s ${DISKDEV} print 1 > /dev/null 2>&1 && {
233 echo "Partition ${DISKPARTDEV} exists."
235 echo "Creating partition ${DISKPARTDEV}."
236 parted -s ${DISKDEV} mkpart primary 1 100%
239 blkid -s TYPE ${DISKPARTDEV} | grep -q -s 'TYPE="xfs"' && {
240 echo "Partition ${DISKPARTDEV} contains xfs file system."
242 echo "Creating xfs filesystem on ${DISKPARTDEV}."
243 mkfs.xfs -f ${DISKPARTDEV}
250 grep -q -s ${DISKPARTDEV} ${FILE} && {
251 echo "Mount entry for ${DISKPARTDEV} is present in ${FILE}."
253 echo "Creating mount entry for ${DISKPARTDEV} in ${FILE}."
254 test -f ${FILE} || touch ${FILE}
255 cp -f -a ${FILE} ${FILE}${BACKUP_SUFFIX}
257 ${DISKPARTDEV} ${MOUNTP} xfs defaults 0 0
261 mount | grep ${MOUNTP} && {
262 echo "${MOUNTP} is already mounted."
264 echo "Mounting ${MOUNTP}."
271 GLUSTER_START_SCRIPT = <<SCRIPT
273 systemctl start glusterd.service
276 #GLUSTER_PROBE_SCRIPT = <<SCRIPT
281 #gluster peer probe ${PEER_IP}
284 GLUSTER_PROBE_SCRIPT = <<SCRIPT
289 for PEER_IP in ${PEER_IPS}
291 # try for some time to reach the other node:
292 for COUNT in $(seq 1 20)
294 gluster peer probe ${PEER_IP} 2> /dev/null && {
303 GLUSTER_WAIT_PEERS_SCRIPT = <<SCRIPT
308 echo "Waiting for $NUM_NODES peers."
310 for count in $(seq 1 60)
312 PEERS=$(gluster pool list | grep -v ^UUID | wc -l)
313 [ "$PEERS" = "$NUM_NODES" ] && {
314 echo "Done waiting: $NUM_NODES peers connected."
321 echo "TIMEOUT waiting for $NUM_NODES peers."
326 GLUSTER_CREATEVOL_SCRIPT = <<SCRIPT
335 MSG="$(gluster volume status ${VOLNAME} 2>&1 1>/dev/null)"
337 [ $RET -eq 0 ] && break
338 [ "$MSG" = 'Another transaction is in progress. Please try again after sometime.' ] || break
343 echo "gluster volume ${VOLNAME} already exists and is active."
347 [ "$MSG" = "Volume ${VOLNAME} does not exist" ] && {
348 echo "Creating gluster volume ${VOLNAME}."
349 echo "cmd: gluster volume create $VOLNAME rep $REP transport tcp $@"
351 MSG=$(gluster volume create $VOLNAME rep $REP transport tcp $@ 2>&1 1>/dev/null)
353 [ $RET -eq 0 ] && break
354 [ "$MSG" = "volume create: $VOLNAME: failed: Another transaction is in progress. Please try again after sometime." ] || break
358 echo "gluster volume create $VOLNAME failed ("$MSG")- trying to force."
361 MSG=$(gluster volume create $VOLNAME rep $REP transport tcp $@ force 2>&1 1>/dev/null)
363 [ $RET -eq 0 ] && break
364 [ "$MSG" = "volume create: $VOLNAME: failed: Another transaction is in progress. Please try again after sometime." ] || break
369 echo "gluster volume create $VOLNAME failed with force ("$MSG")- giving up"
374 MSG="$(gluster volume status ${VOLNAME} 2>&1 1>/dev/null)"
376 [ $RET -eq 0 ] && break
377 [ "$MSG" = 'Another transaction is in progress. Please try again after sometime.' ] || break
382 echo "gluster volume ${VOLNAME} is already started."
387 [ "$MSG" = "Volume ${VOLNAME} is not started" ] && {
388 echo "starting gluster volume ${VOLNAME}."
389 gluster volume start $VOLNAME
391 echo "Error: 'gluster volume status ${VOLNAME}' gave '$MSG' ($RET)"
399 GLUSTER_MOUNT_SCRIPT = <<SCRIPT
407 MOUNTDEV="127.0.0.1:/${VOLNAME}"
411 #mount -t glusterfs ${MOUNTDEV} ${MOUNTPT}
413 BACKUP_SUFFIX=".orig.$(date +%Y%m%d-%H%M%S)"
417 grep -q -s "${MOUNTPT}" ${FILE} || {
418 test -f ${FILE} || touch ${FILE}
419 cp -f -a ${FILE} ${FILE}${BACKUP_SUFFIX}
422 ${MOUNTDEV} ${MOUNTPT} glusterfs defaults,selinux 0 0
426 mount | grep -q -s ${MOUNTPT} && {
427 echo "${MOUNTPT} is already mounted."
429 echo "Mounting ${MOUNTPT}."
436 CTDB_STOP_SCRIPT = <<SCRIPT
438 systemctl stop ctdb.service
441 CTDB_CREATE_NODES_SCRIPT = <<SCRIPT
444 BACKUP_SUFFIX=".orig.$(date +%Y%m%d-%H%M%S)"
449 test -f ${FILE} || touch ${FILE}
450 cp -f -a ${FILE} ${FILE}${BACKUP_SUFFIX}
453 for IP in ${NODES_IPS}
455 echo "$IP" >> ${FILE}
459 CTDB_CREATE_PUBADDRS_SCRIPT = <<SCRIPT
462 BACKUP_SUFFIX=".orig.$(date +%Y%m%d-%H%M%S)"
466 FILE=/etc/ctdb/public_addresses
467 test -f ${FILE} || touch ${FILE}
468 cp -f -a ${FILE} ${FILE}${BACKUP_SUFFIX}
473 echo ${IP} >> ${FILE}
477 CTDB_CREATE_CONF_SCRIPT = <<SCRIPT
480 BACKUP_SUFFIX=".orig.$(date +%Y%m%d-%H%M%S)"
482 RECLOCKDIR=/gluster/gv0/ctdb
483 mkdir -p ${RECLOCKDIR}
484 RECLOCKFILE=${RECLOCKDIR}/reclock
486 PUBLIC_ADDRESSES_FILE=/etc/ctdb/public_addresses
487 NODES_FILE=/etc/ctdb/nodes
489 FILE=/etc/sysconfig/ctdb
490 test -f ${FILE} || touch ${FILE}
491 cp -f -a ${FILE} ${FILE}${BACKUP_SUFFIX}
495 CTDB_NODES=${NODES_FILE}
496 #CTDB_PUBLIC_ADDRESSES=${PUBLIC_ADDRESSES_FILE}
497 CTDB_RECOVERY_LOCK=${RECLOCKFILE}
498 CTDB_MANAGES_SAMBA="yes"
499 CTDB_SAMBA_SKIP_SHARE_CHECK="yes"
500 #CTDB_MANAGES_WINBIND="yes"
504 SAMBA_CREATE_CONF_SCRIPT = <<SCRIPT
507 BACKUP_SUFFIX=".orig.$(date +%Y%m%d-%H%M%S)"
513 mkdir -p ${GLUSTER_VOL_MOUNT}/share1
514 chmod -R 0777 ${GLUSTER_VOL_MOUNT}/share1
516 mkdir -p ${GLUSTER_VOL_MOUNT}/share2
517 chmod -R 0777 ${GLUSTER_VOL_MOUNT}/share2
519 FILE=/etc/samba/smb.conf
520 test -f ${FILE} || touch ${FILE}
521 cp -f -a ${FILE} ${FILE}${BACKUP_SUFFIX}
526 netbios name = sambacluster
535 vfs objects = acl_xattr glusterfs
536 glusterfs:volume = ${GLUSTER_VOL}
537 kernel share modes = no
541 path = ${GLUSTER_VOL_MOUNT}/share2
542 vfs objects = acl_xattr
547 CTDB_START_SCRIPT = <<SCRIPT
549 systemctl start ctdb.service
552 # The vagrant machine definitions
555 Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
557 if Vagrant.has_plugin?("vagrant-cachier")
558 config.cache.scope = :box
561 # just let one node do the probing
564 vms.each do |machine|
565 config.vm.define machine[:hostname] do |node|
566 node.vm.box = machine[:provider][:libvirt][:box]
567 node.vm.hostname = machine[:hostname]
569 node.vm.provider :libvirt do |libvirt|
570 libvirt.default_prefix = machine[:provider][:libvirt][:prefix]
571 libvirt.memory = 1024
572 libvirt.storage :file, :size => '64M', :device => 'vdb'
573 libvirt.storage :file, :size => '10G', :device => 'vdc'
575 machine[:networks].each do |net|
576 if not net[:ipv4] == ''
577 node.vm.network :private_network, :ip => net[:ipv4]
583 # There is some problem with the fedora base box:
584 # Upon first boot, ifdown eth1 fails and the dhclient
585 # keep being active. Simply bringing down and up again
586 # the interface is not sufficient. We need to restart
587 # NetworkManager in order to teach it to not feel
588 # responsible for the interface any more.
589 node.vm.provision "net_fix_initial", type: "shell" do |s|
590 s.inline = NET_FIX_INITIAL_SCRIPT
593 node.vm.provision "install", type: "shell" do |s|
594 s.inline = INSTALL_SCRIPT
597 # There is some problem with the fedora base box:
598 # We need to up the interface on reboots.
599 # It does not come up automatically.
600 node.vm.provision "net_fix_always", type: "shell", run: "always" do |s|
601 s.inline = NET_FIX_ALWAYS_SCRIPT
602 s.args = [ '/gluster/gv0', '/gluster/gv1' ]
605 # multiple privisioners with same name possible?
606 node.vm.provision "xfs_0", type: "shell" do |s|
607 s.inline = XFS_SCRIPT
608 #s.args = [ "vdb", "/export/gluster/brick1" ]
612 node.vm.provision "xfs_1", type: "shell" do |s|
613 s.inline = XFS_SCRIPT
614 #s.args = [ "vdc" , "/export/gluster/brick2" ]
618 node.vm.provision "gluster_start", type: "shell" do |s|
619 s.inline = GLUSTER_START_SCRIPT
624 node.vm.provision "gluster_probe", type: "shell" do |s|
625 s.inline = GLUSTER_PROBE_SCRIPT
626 s.args = cluster_internal_ips
630 node.vm.provision "gluster_wait_peers", type: "shell" do |s|
631 s.inline = GLUSTER_WAIT_PEERS_SCRIPT
632 s.args = [ cluster_internal_ips.length ]
635 node.vm.provision "gluster_createvol_0", type: "shell" do |s|
636 mount_points = cluster_internal_ips.map do |ip|
637 "#{ip}:/export/vdb1/brick"
639 s.inline = GLUSTER_CREATEVOL_SCRIPT
640 s.args = [ "gv0", "3" ] + mount_points
643 node.vm.provision "gluster_mount_0", type: "shell" do |s|
644 s.inline = GLUSTER_MOUNT_SCRIPT
645 s.args = [ "gv0", "/gluster/gv0" ]
648 node.vm.provision "gluster_createvol_1", type: "shell" do |s|
649 mount_points = cluster_internal_ips.map do |ip|
650 "#{ip}:/export/vdc1/brick"
652 s.inline = GLUSTER_CREATEVOL_SCRIPT
653 s.args = [ "gv1", "3" ] + mount_points
656 node.vm.provision "gluster_mount_1", type: "shell" do |s|
657 s.inline = GLUSTER_MOUNT_SCRIPT
658 s.args = [ "gv1", "/gluster/gv1" ]
662 # ctdb / samba config
665 node.vm.provision "ctdb_stop", type: "shell" do |s|
666 s.inline = CTDB_STOP_SCRIPT
669 node.vm.provision "ctdb_create_nodes", type: "shell" do |s|
670 s.inline = CTDB_CREATE_NODES_SCRIPT
671 s.args = cluster_internal_ips
674 #node.vm.provision "ctdb_create_pubaddrs", type: "shell" do |s|
675 # s.inline = CTDB_CREATE_PUBADDRS_SCRIPT
679 node.vm.provision "ctdb_create_conf", type: "shell" do |s|
680 s.inline = CTDB_CREATE_CONF_SCRIPT
683 node.vm.provision "samba_create_conf", type: "shell" do |s|
684 s.inline = SAMBA_CREATE_CONF_SCRIPT
685 s.args = [ "gv1", "/gluster/gv1" ]
688 node.vm.provision "ctdb_start", type: "shell" do |s|
689 s.inline = CTDB_START_SCRIPT