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 mountd. 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
205 XFS_SCRIPT = <<SCRIPT
210 DISKDEV="/dev/${DEVICE}"
211 DISKPARTDEV="/dev/${PARTDEV}"
213 MOUNTP=/export/${PARTDEV}
214 BRICKD=${MOUNTP}/brick
216 BACKUP_SUFFIX=".orig.$(date +%Y%m%d-%H%M%S)"
218 parted -s ${DISKDEV} print > /dev/null 2>&1 && {
219 echo "Label exists on ${DISKDEV}."
221 echo "Creating label on ${DISKDEV}."
222 parted -s ${DISKDEV} mklabel msdos
225 parted -s ${DISKDEV} print 1 > /dev/null 2>&1 && {
226 echo "Partition ${DISKPARTDEV} exists."
228 echo "Creating partition ${DISKPARTDEV}."
229 parted -s ${DISKDEV} mkpart primary 1 100%
232 blkid -s TYPE ${DISKPARTDEV} | grep -q -s 'TYPE="xfs"' && {
233 echo "Partition ${DISKPARTDEV} contains xfs file system."
235 echo "Creating xfs filesystem on ${DISKPARTDEV}."
236 mkfs.xfs -f ${DISKPARTDEV}
243 grep -q -s ${DISKPARTDEV} ${FILE} && {
244 echo "Mount entry for ${DISKPARTDEV} is present in ${FILE}."
246 echo "Creating mount entry for ${DISKPARTDEV} in ${FILE}."
247 test -f ${FILE} || touch ${FILE}
248 cp -f -a ${FILE} ${FILE}${BACKUP_SUFFIX}
250 ${DISKPARTDEV} ${MOUNTP} xfs defaults 0 0
254 mount | grep ${MOUNTP} && {
255 echo "${MOUNTP} is already mounted."
257 echo "Mounting ${MOUNTP}."
264 GLUSTER_START_SCRIPT = <<SCRIPT
266 systemctl start glusterd.service
269 GLUSTER_PROBE_SCRIPT = <<SCRIPT
274 echo "peer probing for [${PEER_IPS}]"
276 for PEER_IP in ${PEER_IPS}
278 echo "peer probing for '${PEER_IP}'"
279 # try for some time to reach the other node:
280 for COUNT in $(seq 1 120)
282 gluster peer probe ${PEER_IP} 2> /dev/null && {
291 GLUSTER_WAIT_PEERS_SCRIPT = <<SCRIPT
296 echo "Waiting for $NUM_NODES peers."
298 for count in $(seq 1 300)
300 PEERS=$(gluster pool list | grep -v ^UUID | wc -l)
301 [ "$PEERS" = "$NUM_NODES" ] && {
302 echo "Done waiting: $NUM_NODES peers connected."
309 echo "TIMEOUT waiting for $NUM_NODES peers."
314 GLUSTER_CREATEVOL_SCRIPT = <<SCRIPT
323 MSG="$(gluster volume status ${VOLNAME} 2>&1 1>/dev/null)"
325 [ $RET -eq 0 ] && break
326 [ "$MSG" = 'Another transaction is in progress. Please try again after sometime.' ] || break
331 echo "gluster volume ${VOLNAME} already exists and is active."
335 [ "$MSG" = "Volume ${VOLNAME} does not exist" ] && {
336 echo "Creating gluster volume ${VOLNAME}."
337 echo "cmd: gluster volume create $VOLNAME rep $REP transport tcp $@"
339 MSG=$(gluster volume create $VOLNAME rep $REP transport tcp $@ 2>&1 1>/dev/null)
341 [ $RET -eq 0 ] && break
342 [ "$MSG" = "volume create: ${VOLNAME}: failed: Volume ${VOLNAME} already exists" ] && {
346 [ "$MSG" = "volume create: $VOLNAME: failed: Another transaction is in progress. Please try again after sometime." ] || break
350 echo "gluster volume create $VOLNAME failed ('$MSG')- trying to force."
353 MSG=$(gluster volume create $VOLNAME rep $REP transport tcp $@ force 2>&1 1>/dev/null)
355 [ $RET -eq 0 ] && break
356 [ "$MSG" = "volume create: ${VOLNAME}: failed: Volume ${VOLNAME} already exists" ] && {
360 [ "$MSG" = "volume create: $VOLNAME: failed: Another transaction is in progress. Please try again after sometime." ] || break
365 echo "gluster volume create $VOLNAME failed with force ('$MSG')- giving up"
370 MSG="$(gluster volume status ${VOLNAME} 2>&1 1>/dev/null)"
372 [ $RET -eq 0 ] && break
373 [ "${MSG}" != "${MSG#Another transaction}" ] || break
378 echo "gluster volume ${VOLNAME} is already started."
383 [ "$MSG" = "Volume ${VOLNAME} is not started" ] && {
384 echo "starting gluster volume ${VOLNAME}."
386 MSG=$(gluster volume start ${VOLNAME} 2>&1 1> /dev/null)
388 [ $RET -eq 0 ] && break
389 [ "$MSG" = "volume start: ${VOLNAME}: failed: Volume ${VOLNAME} already started" ] && {
393 [ "$MSG" = "volume start: ${VOLNAME}: failed: Another transaction is in progress. Please try again after sometime." ] || break
397 echo "gluster volume start ${VOLNAME} failed ('$MSG')."
401 echo "Error: 'gluster volume status ${VOLNAME}' gave '$MSG' ($RET)"
409 GLUSTER_MOUNT_SCRIPT = <<SCRIPT
417 MOUNTDEV="127.0.0.1:/${VOLNAME}"
421 #mount -t glusterfs ${MOUNTDEV} ${MOUNTPT}
423 BACKUP_SUFFIX=".orig.$(date +%Y%m%d-%H%M%S)"
427 grep -q -s "${MOUNTPT}" ${FILE} || {
428 test -f ${FILE} || touch ${FILE}
429 cp -f -a ${FILE} ${FILE}${BACKUP_SUFFIX}
432 ${MOUNTDEV} ${MOUNTPT} glusterfs defaults,selinux 0 0
436 mount | grep -q -s ${MOUNTPT} && {
437 echo "${MOUNTPT} is already mounted."
439 echo "Mounting ${MOUNTPT}."
446 CTDB_STOP_SCRIPT = <<SCRIPT
448 systemctl stop ctdb.service
451 CTDB_CREATE_NODES_SCRIPT = <<SCRIPT
454 BACKUP_SUFFIX=".orig.$(date +%Y%m%d-%H%M%S)"
459 test -f ${FILE} || touch ${FILE}
460 cp -f -a ${FILE} ${FILE}${BACKUP_SUFFIX}
463 for IP in ${NODES_IPS}
465 echo "$IP" >> ${FILE}
469 CTDB_CREATE_PUBADDRS_SCRIPT = <<SCRIPT
472 BACKUP_SUFFIX=".orig.$(date +%Y%m%d-%H%M%S)"
476 FILE=/etc/ctdb/public_addresses
477 test -f ${FILE} || touch ${FILE}
478 cp -f -a ${FILE} ${FILE}${BACKUP_SUFFIX}
483 echo ${IP} >> ${FILE}
487 CTDB_CREATE_CONF_SCRIPT = <<SCRIPT
490 BACKUP_SUFFIX=".orig.$(date +%Y%m%d-%H%M%S)"
492 RECLOCKDIR=/gluster/gv0/ctdb
493 mkdir -p ${RECLOCKDIR}
494 RECLOCKFILE=${RECLOCKDIR}/reclock
496 PUBLIC_ADDRESSES_FILE=/etc/ctdb/public_addresses
497 NODES_FILE=/etc/ctdb/nodes
499 FILE=/etc/sysconfig/ctdb
500 test -f ${FILE} || touch ${FILE}
501 cp -f -a ${FILE} ${FILE}${BACKUP_SUFFIX}
505 CTDB_NODES=${NODES_FILE}
506 #CTDB_PUBLIC_ADDRESSES=${PUBLIC_ADDRESSES_FILE}
507 CTDB_RECOVERY_LOCK=${RECLOCKFILE}
508 CTDB_MANAGES_SAMBA="yes"
509 CTDB_SAMBA_SKIP_SHARE_CHECK="yes"
510 #CTDB_MANAGES_WINBIND="yes"
514 SAMBA_CREATE_CONF_SCRIPT = <<SCRIPT
517 BACKUP_SUFFIX=".orig.$(date +%Y%m%d-%H%M%S)"
523 mkdir -p ${GLUSTER_VOL_MOUNT}/share1
524 chmod -R 0777 ${GLUSTER_VOL_MOUNT}/share1
526 mkdir -p ${GLUSTER_VOL_MOUNT}/share2
527 chmod -R 0777 ${GLUSTER_VOL_MOUNT}/share2
529 FILE=/etc/samba/smb.conf
530 test -f ${FILE} || touch ${FILE}
531 cp -f -a ${FILE} ${FILE}${BACKUP_SUFFIX}
536 netbios name = sambacluster
545 vfs objects = acl_xattr glusterfs
546 glusterfs:volume = ${GLUSTER_VOL}
547 kernel share modes = no
551 path = ${GLUSTER_VOL_MOUNT}/share2
552 vfs objects = acl_xattr
557 CTDB_START_SCRIPT = <<SCRIPT
559 systemctl start ctdb.service
562 # The vagrant machine definitions
565 Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
567 if Vagrant.has_plugin?("vagrant-cachier")
568 config.cache.scope = :machine
569 #config.cache.scope = :box
572 config.cache.synced_folder_opts = {
574 # The nolock option can be useful for an NFSv3 client that wants to avoid the
575 # NLM sideband protocol. Without this option, apt-get might hang if it tries
576 # to lock files needed for /var/cache/* operations. All of this can be avoided
577 # by using NFSv4 everywhere. Please note that the tcp option is not the default.
578 #mount_options: ['rw', 'vers=3', 'tcp', 'nolock']
581 # just let one node do the probing
584 vms.each do |machine|
585 config.vm.define machine[:hostname] do |node|
586 node.vm.box = machine[:provider][:libvirt][:box]
587 node.vm.hostname = machine[:hostname]
589 node.vm.provider :libvirt do |libvirt|
590 libvirt.default_prefix = machine[:provider][:libvirt][:prefix]
591 libvirt.memory = 1024
592 libvirt.storage :file, :size => '64M', :device => 'vdb'
593 libvirt.storage :file, :size => '10G', :device => 'vdc'
595 machine[:networks].each do |net|
596 if not net[:ipv4] == ''
597 node.vm.network :private_network, :ip => net[:ipv4]
603 node.vm.provision "selinux", type: "shell" do |s|
604 s.path = "provision/shell/sys/selinux-off.sh"
607 # There is some problem with the fedora base box:
608 # Upon first boot, ifdown eth1 fails and the dhclient
609 # keep being active. Simply bringing down and up again
610 # the interface is not sufficient. We need to restart
611 # NetworkManager in order to teach it to not feel
612 # responsible for the interface any more.
613 node.vm.provision "net_fix_initial", type: "shell" do |s|
614 s.inline = NET_FIX_INITIAL_SCRIPT
617 node.vm.provision "install", type: "shell" do |s|
618 s.path = "provision/shell/sys/install-yum.sh"
619 s.args = [ "xfsprogs",
623 "glusterfs-geo-replication",
627 "samba-vfs-glusterfs" ]
630 # There is some problem with the fedora base box:
631 # We need to up the interface on reboots.
632 # It does not come up automatically.
633 node.vm.provision "net_fix_always", type: "shell", run: "always" do |s|
634 s.inline = NET_FIX_ALWAYS_SCRIPT
635 s.args = [ '/gluster/gv0', '/gluster/gv1' ]
638 # multiple privisioners with same name possible?
639 node.vm.provision "xfs_0", type: "shell" do |s|
640 s.inline = XFS_SCRIPT
641 #s.args = [ "vdb", "/export/gluster/brick1" ]
645 node.vm.provision "xfs_1", type: "shell" do |s|
646 s.inline = XFS_SCRIPT
647 #s.args = [ "vdc" , "/export/gluster/brick2" ]
651 node.vm.provision "gluster_start", type: "shell" do |s|
652 s.inline = GLUSTER_START_SCRIPT
657 node.vm.provision "gluster_probe", type: "shell" do |s|
658 s.inline = GLUSTER_PROBE_SCRIPT
659 s.args = cluster_internal_ips
663 node.vm.provision "gluster_wait_peers", type: "shell" do |s|
664 s.inline = GLUSTER_WAIT_PEERS_SCRIPT
665 s.args = [ cluster_internal_ips.length ]
668 node.vm.provision "gluster_createvol_0", type: "shell" do |s|
669 mount_points = cluster_internal_ips.map do |ip|
670 "#{ip}:/export/vdb1/brick"
672 s.inline = GLUSTER_CREATEVOL_SCRIPT
673 s.args = [ "gv0", "3" ] + mount_points
676 node.vm.provision "gluster_mount_0", type: "shell" do |s|
677 s.inline = GLUSTER_MOUNT_SCRIPT
678 s.args = [ "gv0", "/gluster/gv0" ]
681 node.vm.provision "gluster_createvol_1", type: "shell" do |s|
682 mount_points = cluster_internal_ips.map do |ip|
683 "#{ip}:/export/vdc1/brick"
685 s.inline = GLUSTER_CREATEVOL_SCRIPT
686 s.args = [ "gv1", "3" ] + mount_points
689 node.vm.provision "gluster_mount_1", type: "shell" do |s|
690 s.inline = GLUSTER_MOUNT_SCRIPT
691 s.args = [ "gv1", "/gluster/gv1" ]
695 # ctdb / samba config
698 node.vm.provision "ctdb_stop", type: "shell" do |s|
699 s.inline = CTDB_STOP_SCRIPT
702 node.vm.provision "ctdb_create_nodes", type: "shell" do |s|
703 s.inline = CTDB_CREATE_NODES_SCRIPT
704 s.args = cluster_internal_ips
707 #node.vm.provision "ctdb_create_pubaddrs", type: "shell" do |s|
708 # s.inline = CTDB_CREATE_PUBADDRS_SCRIPT
712 node.vm.provision "ctdb_create_conf", type: "shell" do |s|
713 s.inline = CTDB_CREATE_CONF_SCRIPT
716 node.vm.provision "samba_create_conf", type: "shell" do |s|
717 s.inline = SAMBA_CREATE_CONF_SCRIPT
718 s.args = [ "gv1", "/gluster/gv1" ]
721 node.vm.provision "ctdb_start", type: "shell" do |s|
722 s.inline = CTDB_START_SCRIPT