From 24844a892c07001bb50eeb443005d3c2fe5d4025 Mon Sep 17 00:00:00 2001 From: James Shubin Date: Sun, 8 Sep 2013 01:28:39 -0400 Subject: This patch adds fact magic to make specifying host uuid's optional. If you would like to be ultra lazy and not specify any uuid's manually, the puppet module can now generate them on your behalf. This will take at least two puppet runs because of the distributed nature of gluster and because the uuid facts must be exported to all the nodes for peering. Please note that if you rebuild a node from scratch, you probably won't get the same UUID. You can either set it manually, or paste one in the /var/lib/puppet/tmp/gluster/uuid/uuid file. Watch the formatting! --- manifests/host.pp | 152 +++++++++++++++++++++++++++++++++++------------------- 1 file changed, 99 insertions(+), 53 deletions(-) (limited to 'manifests') diff --git a/manifests/host.pp b/manifests/host.pp index 9a31f97..7bd461d 100644 --- a/manifests/host.pp +++ b/manifests/host.pp @@ -20,69 +20,115 @@ # only the host holding the vip is allowed to execute cluster peer operations. define gluster::host( - $uuid + $uuid = '' # if empty, puppet will attempt to use the gluster fact ) { + include gluster::vardir + + #$vardir = $::gluster::vardir::module_vardir # with trailing slash + $vardir = regsubst($::gluster::vardir::module_vardir, '\/$', '') + # if we're on itself if ( "${fqdn}" == "${name}" ) { - # set a unique uuid per host - file { '/var/lib/glusterd/glusterd.info': - content => template('gluster/glusterd.info.erb'), - owner => root, - group => root, - mode => 600, # u=rw,go=r - seltype => 'glusterd_var_lib_t', - seluser => 'unconfined_u', - ensure => present, - require => File['/var/lib/glusterd/'], + # don't purge the uuid file generated within + file { "${vardir}/uuid/": + ensure => directory, # make sure this is a directory + recurse => false, # don't recurse into directory + purge => false, # don't purge unmanaged files + force => false, # don't purge subdirs and links + require => File["${vardir}/"], } - } else { - # set uuid= - exec { "/bin/echo 'uuid=${uuid}' >> '/var/lib/glusterd/peers/${uuid}'": - logoutput => on_failure, - unless => "/bin/grep -qF 'uuid=' '/var/lib/glusterd/peers/${uuid}'", - notify => File['/var/lib/glusterd/peers/'], # propagate the notify up - before => File["/var/lib/glusterd/peers/${uuid}"], - alias => "gluster-host-uuid-${name}", - # FIXME: doing this causes a dependency cycle! adding - # the Package[] require doesn't. It would be most - # correct to require the peers/ folder, but since it's - # not working, requiring the Package[] will still give - # us the same result. (Package creates peers/ folder). - # NOTE: it's possible the cycle is a bug in puppet or a - # bug in the dependencies somewhere else in this module. - #require => File['/var/lib/glusterd/peers/'], - require => Package['glusterfs-server'], + + $valid_uuid = "${uuid}" ? { + # fact from the data generated in: ${vardir}/uuid/uuid + '' => "${::gluster_uuid}", + default => "${uuid}", } + if "${valid_uuid}" == '' { + fail('No valid UUID exists yet!') + } else { + # set a unique uuid per host + file { '/var/lib/glusterd/glusterd.info': + content => template('gluster/glusterd.info.erb'), + owner => root, + group => root, + mode => 600, # u=rw,go=r + seltype => 'glusterd_var_lib_t', + seluser => 'unconfined_u', + ensure => present, + require => File['/var/lib/glusterd/'], + } - # set state= - exec { "/bin/echo 'state=3' >> '/var/lib/glusterd/peers/${uuid}'": - logoutput => on_failure, - unless => "/bin/grep -qF 'state=' '/var/lib/glusterd/peers/${uuid}'", - notify => File['/var/lib/glusterd/peers/'], # propagate the notify up - before => File["/var/lib/glusterd/peers/${uuid}"], - require => Exec["gluster-host-uuid-${name}"], - alias => "gluster-host-state-${name}", + # NOTE: $name here should probably be the fqdn... + @@file { "${vardir}/uuid/uuid_${name}": + content => "${valid_uuid}\n", + tag => 'gluster_uuid', + owner => root, + group => root, + mode => 600, + ensure => present, + } } - # set hostname1=... - exec { "/bin/echo 'hostname1=${name}' >> '/var/lib/glusterd/peers/${uuid}'": - logoutput => on_failure, - unless => "/bin/grep -qF 'hostname1=' '/var/lib/glusterd/peers/${uuid}'", - notify => File['/var/lib/glusterd/peers/'], # propagate the notify up - before => File["/var/lib/glusterd/peers/${uuid}"], - require => Exec["gluster-host-state-${name}"], + File <<| tag == 'gluster_uuid' |>> { # collect to make facts } - # tag the file so it doesn't get removed by purge - file { "/var/lib/glusterd/peers/${uuid}": - ensure => present, - notify => File['/var/lib/glusterd/peers/'], # propagate the notify up - owner => root, - group => root, - # NOTE: this mode was found by inspecting the process - mode => 600, # u=rw,go=r - seltype => 'glusterd_var_lib_t', - seluser => 'unconfined_u', + } else { + $valid_uuid = "${uuid}" ? { + # fact from the data generated in: ${vardir}/uuid/uuid + '' => getvar("gluster_uuid_${name}"), # fact ! + default => "${uuid}", + } + if "${valid_uuid}" == '' { + notice('No valid UUID exists yet.') # different msg + } else { + # set uuid= + exec { "/bin/echo 'uuid=${valid_uuid}' >> '/var/lib/glusterd/peers/${valid_uuid}'": + logoutput => on_failure, + unless => "/bin/grep -qF 'uuid=' '/var/lib/glusterd/peers/${valid_uuid}'", + notify => File['/var/lib/glusterd/peers/'], # propagate the notify up + before => File["/var/lib/glusterd/peers/${valid_uuid}"], + alias => "gluster-host-uuid-${name}", + # FIXME: doing this causes a dependency cycle! adding + # the Package[] require doesn't. It would be most + # correct to require the peers/ folder, but since it's + # not working, requiring the Package[] will still give + # us the same result. (Package creates peers/ folder). + # NOTE: it's possible the cycle is a bug in puppet or a + # bug in the dependencies somewhere else in this module. + #require => File['/var/lib/glusterd/peers/'], + require => Package['glusterfs-server'], + } + + # set state= + exec { "/bin/echo 'state=3' >> '/var/lib/glusterd/peers/${valid_uuid}'": + logoutput => on_failure, + unless => "/bin/grep -qF 'state=' '/var/lib/glusterd/peers/${valid_uuid}'", + notify => File['/var/lib/glusterd/peers/'], # propagate the notify up + before => File["/var/lib/glusterd/peers/${valid_uuid}"], + require => Exec["gluster-host-uuid-${name}"], + alias => "gluster-host-state-${name}", + } + + # set hostname1=... + exec { "/bin/echo 'hostname1=${name}' >> '/var/lib/glusterd/peers/${valid_uuid}'": + logoutput => on_failure, + unless => "/bin/grep -qF 'hostname1=' '/var/lib/glusterd/peers/${valid_uuid}'", + notify => File['/var/lib/glusterd/peers/'], # propagate the notify up + before => File["/var/lib/glusterd/peers/${valid_uuid}"], + require => Exec["gluster-host-state-${name}"], + } + + # tag the file so it doesn't get removed by purge + file { "/var/lib/glusterd/peers/${valid_uuid}": + ensure => present, + notify => File['/var/lib/glusterd/peers/'], # propagate the notify up + owner => root, + group => root, + # NOTE: this mode was found by inspecting the process + mode => 600, # u=rw,go=r + seltype => 'glusterd_var_lib_t', + seluser => 'unconfined_u', + } } } } -- cgit