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
205 XFS_SCRIPT = <<SCRIPT
210 DISKDEV="/dev/${DEVICE}"
211 DISKPARTDEV="/dev/${PARTDEV}"
213 MOUNTP=${EXPORT_BASEDIR}/${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}."
265 GLUSTER_PROBE_SCRIPT = <<SCRIPT
270 echo "peer probing for [${PEER_IPS}]"
272 for PEER_IP in ${PEER_IPS}
274 echo "peer probing for '${PEER_IP}'"
276 for COUNT in $(seq 1 120)
278 gluster peer probe ${PEER_IP} 2> /dev/null && {
279 echo "reached node '${PEER_IP}'"
286 gluster peer probe ${PEER_IP} 2> /dev/null || {
287 echo "did not reach node '${PEER_IP}' - stopping here"
294 GLUSTER_WAIT_PEERS_SCRIPT = <<SCRIPT
300 echo "Waiting for $NUM_NODES peers."
302 for count in $(seq 1 ${TIMEOUT})
304 PEERS=$(gluster pool list | grep -v ^UUID | wc -l)
305 [ "$PEERS" = "$NUM_NODES" ] && {
306 echo "Done waiting: $NUM_NODES peers connected."
313 echo "TIMEOUT waiting for $NUM_NODES peers."
318 GLUSTER_CREATEVOL_SCRIPT = <<SCRIPT
327 MSG="$(gluster volume status ${VOLNAME} 2>&1 1>/dev/null)"
329 [ $RET -eq 0 ] && break
330 [ "${MSG}" != "${MSG#Another transaction is in progress}" ] || break
335 echo "gluster volume ${VOLNAME} already exists and is active."
339 [ "$MSG" = "Volume ${VOLNAME} does not exist" ] && {
340 echo "Creating gluster volume ${VOLNAME}."
341 echo "cmd: gluster volume create $VOLNAME rep $REP transport tcp $@"
343 MSG=$(gluster volume create $VOLNAME rep $REP transport tcp $@ 2>&1 1>/dev/null)
345 [ $RET -eq 0 ] && break
346 [ "$MSG" = "volume create: ${VOLNAME}: failed: Volume ${VOLNAME} already exists" ] && {
350 [ "${MSG}" != "${MSG#Another transaction is in progress}" ] || break
354 echo "gluster volume create $VOLNAME failed ('$MSG')- trying to force."
357 MSG=$(gluster volume create $VOLNAME rep $REP transport tcp $@ force 2>&1 1>/dev/null)
359 [ $RET -eq 0 ] && break
360 [ "$MSG" = "volume create: ${VOLNAME}: failed: Volume ${VOLNAME} already exists" ] && {
364 [ "${MSG}" != "${MSG#Another transaction is in progress}" ] || 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}" != "${MSG#Another transaction is in progress}" ] || break
382 echo "gluster volume ${VOLNAME} is already started."
387 [ "$MSG" = "Volume ${VOLNAME} is not started" ] && {
388 echo "starting gluster volume ${VOLNAME}."
390 MSG=$(gluster volume start ${VOLNAME} 2>&1 1> /dev/null)
392 [ $RET -eq 0 ] && break
393 [ "$MSG" = "volume start: ${VOLNAME}: failed: Volume ${VOLNAME} already started" ] && {
397 [ "${MSG}" != "${MSG#Another transaction is in progress}" ] || break
401 echo "gluster volume start ${VOLNAME} failed ('$MSG')."
405 echo "Error: 'gluster volume status ${VOLNAME}' gave '$MSG' ($RET)"
413 GLUSTER_MOUNT_SCRIPT = <<SCRIPT
421 MOUNTDEV="127.0.0.1:/${VOLNAME}"
425 BACKUP_SUFFIX=".orig.$(date +%Y%m%d-%H%M%S)"
429 grep -q -s "${MOUNTPT}" ${FILE} || {
430 test -f ${FILE} || touch ${FILE}
431 cp -f -a ${FILE} ${FILE}${BACKUP_SUFFIX}
434 ${MOUNTDEV} ${MOUNTPT} glusterfs defaults,selinux 0 0
438 mount | grep -q -s ${MOUNTPT} && {
439 echo "${MOUNTPT} is already mounted."
441 echo "Mounting ${MOUNTPT}."
447 CTDB_CREATE_NODES_SCRIPT = <<SCRIPT
450 BACKUP_SUFFIX=".orig.$(date +%Y%m%d-%H%M%S)"
455 test -f ${FILE} || touch ${FILE}
456 cp -f -a ${FILE} ${FILE}${BACKUP_SUFFIX}
459 for IP in ${NODES_IPS}
461 echo "$IP" >> ${FILE}
465 CTDB_CREATE_PUBADDRS_SCRIPT = <<SCRIPT
468 BACKUP_SUFFIX=".orig.$(date +%Y%m%d-%H%M%S)"
472 FILE=/etc/ctdb/public_addresses
473 test -f ${FILE} || touch ${FILE}
474 cp -f -a ${FILE} ${FILE}${BACKUP_SUFFIX}
479 echo ${IP} >> ${FILE}
483 CTDB_CREATE_CONF_SCRIPT = <<SCRIPT
486 BACKUP_SUFFIX=".orig.$(date +%Y%m%d-%H%M%S)"
488 RECLOCKDIR=/gluster/gv0/ctdb
489 mkdir -p ${RECLOCKDIR}
490 RECLOCKFILE=${RECLOCKDIR}/reclock
492 PUBLIC_ADDRESSES_FILE=/etc/ctdb/public_addresses
493 NODES_FILE=/etc/ctdb/nodes
495 FILE=/etc/sysconfig/ctdb
496 test -f ${FILE} || touch ${FILE}
497 cp -f -a ${FILE} ${FILE}${BACKUP_SUFFIX}
501 CTDB_NODES=${NODES_FILE}
502 #CTDB_PUBLIC_ADDRESSES=${PUBLIC_ADDRESSES_FILE}
503 CTDB_RECOVERY_LOCK=${RECLOCKFILE}
504 CTDB_MANAGES_SAMBA="yes"
505 CTDB_SAMBA_SKIP_SHARE_CHECK="yes"
506 #CTDB_MANAGES_WINBIND="yes"
510 SAMBA_CREATE_CONF_SCRIPT = <<SCRIPT
513 BACKUP_SUFFIX=".orig.$(date +%Y%m%d-%H%M%S)"
519 mkdir -p ${GLUSTER_VOL_MOUNT}/share1
520 chmod -R 0777 ${GLUSTER_VOL_MOUNT}/share1
522 mkdir -p ${GLUSTER_VOL_MOUNT}/share2
523 chmod -R 0777 ${GLUSTER_VOL_MOUNT}/share2
525 FILE=/etc/samba/smb.conf
526 test -f ${FILE} || touch ${FILE}
527 cp -f -a ${FILE} ${FILE}${BACKUP_SUFFIX}
532 netbios name = sambacluster
541 vfs objects = acl_xattr glusterfs
542 glusterfs:volume = ${GLUSTER_VOL}
543 kernel share modes = no
547 path = ${GLUSTER_VOL_MOUNT}/share2
548 vfs objects = acl_xattr
554 # The vagrant machine definitions
557 Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
559 config.vm.synced_folder ".", "/vagrant", disabled: true
561 #if Vagrant.has_plugin?("vagrant-cachier")
562 # config.cache.scope = :machine
563 # #config.cache.scope = :box
565 # config.cache.synced_folder_opts = {
567 # # The nolock option can be useful for an NFSv3 client that wants to avoid the
568 # # NLM sideband protocol. Without this option, apt-get might hang if it tries
569 # # to lock files needed for /var/cache/* operations. All of this can be avoided
570 # # by using NFSv4 everywhere. Please note that the tcp option is not the default.
571 # #mount_options: ['rw', 'vers=3', 'tcp', 'nolock']
575 # just let one node do the probing
578 vms.each do |machine|
579 config.vm.define machine[:hostname] do |node|
580 node.vm.box = machine[:provider][:libvirt][:box]
581 node.vm.hostname = machine[:hostname]
583 node.vm.provider :libvirt do |libvirt|
584 libvirt.default_prefix = machine[:provider][:libvirt][:prefix]
585 libvirt.memory = 1024
586 libvirt.storage :file, :size => '64M', :device => 'vdb'
587 libvirt.storage :file, :size => '10G', :device => 'vdc'
589 machine[:networks].each do |net|
590 if not net[:ipv4] == ''
591 node.vm.network :private_network, :ip => net[:ipv4]
597 node.vm.provision "selinux", type: "shell" do |s|
598 s.path = "provision/shell/sys/selinux-off.sh"
601 # There is some problem with the fedora base box:
602 # Upon first boot, ifdown eth1 fails and the dhclient
603 # keep being active. Simply bringing down and up again
604 # the interface is not sufficient. We need to restart
605 # NetworkManager in order to teach it to not feel
606 # responsible for the interface any more.
607 ###node.vm.provision "net_fix_initial", type: "shell" do |s|
608 ### s.inline = NET_FIX_INITIAL_SCRIPT
611 node.vm.provision "install", type: "shell" do |s|
612 s.path = "provision/shell/sys/install-yum.sh"
613 s.args = [ "xfsprogs",
617 "glusterfs-geo-replication",
621 "samba-vfs-glusterfs" ]
624 # There is some problem with the fedora base box:
625 # We need to up the interface on reboots.
626 # It does not come up automatically.
627 ###node.vm.provision "net_fix_always", type: "shell", run: "always" do |s|
628 ### s.inline = NET_FIX_ALWAYS_SCRIPT
629 ### s.args = [ '/gluster/gv0', '/gluster/gv1' ]
632 # multiple privisioners with same name possible?
633 node.vm.provision "xfs_0", type: "shell" do |s|
634 s.inline = XFS_SCRIPT
635 s.args = [ "vdb", "/export" ]
638 node.vm.provision "xfs_1", type: "shell" do |s|
639 s.inline = XFS_SCRIPT
640 s.args = [ "vdc", "/export" ]
643 node.vm.provision "gluster_start", type: "shell" do |s|
644 s.path = "provision/shell/gluster/gluster-start.sh"
649 node.vm.provision "gluster_probe", type: "shell" do |s|
650 s.inline = GLUSTER_PROBE_SCRIPT
651 s.args = cluster_internal_ips
656 node.vm.provision "gluster_wait_peers", type: "shell" do |s|
657 s.inline = GLUSTER_WAIT_PEERS_SCRIPT
658 s.args = [ cluster_internal_ips.length, 300]
661 node.vm.provision "gluster_createvol_0", type: "shell" do |s|
662 mount_points = cluster_internal_ips.map do |ip|
663 "#{ip}:/export/vdb1/brick"
665 s.inline = GLUSTER_CREATEVOL_SCRIPT
666 s.args = [ "gv0", "3" ] + mount_points
669 node.vm.provision "gluster_mount_0", type: "shell" do |s|
670 s.inline = GLUSTER_MOUNT_SCRIPT
671 s.args = [ "gv0", "/gluster/gv0" ]
674 node.vm.provision "gluster_createvol_1", type: "shell" do |s|
675 mount_points = cluster_internal_ips.map do |ip|
676 "#{ip}:/export/vdc1/brick"
678 s.inline = GLUSTER_CREATEVOL_SCRIPT
679 s.args = [ "gv1", "3" ] + mount_points
682 node.vm.provision "gluster_mount_1", type: "shell" do |s|
683 s.inline = GLUSTER_MOUNT_SCRIPT
684 s.args = [ "gv1", "/gluster/gv1" ]
688 # ctdb / samba config
691 node.vm.provision "ctdb_stop", type: "shell" do |s|
692 s.path = "provision/shell/ctdb/ctdb-stop.sh"
695 node.vm.provision "ctdb_create_nodes", type: "shell" do |s|
696 s.inline = CTDB_CREATE_NODES_SCRIPT
697 s.args = cluster_internal_ips
700 #node.vm.provision "ctdb_create_pubaddrs", type: "shell" do |s|
701 # s.inline = CTDB_CREATE_PUBADDRS_SCRIPT
705 node.vm.provision "ctdb_create_conf", type: "shell" do |s|
706 s.inline = CTDB_CREATE_CONF_SCRIPT
709 node.vm.provision "samba_create_conf", type: "shell" do |s|
710 s.inline = SAMBA_CREATE_CONF_SCRIPT
711 s.args = [ "gv1", "/gluster/gv1" ]
714 node.vm.provision "ctdb_start", type: "shell" do |s|
715 s.path = "provision/shell/ctdb/ctdb-start.sh"