From 8da4002f83e6505c7c09042df1c10cb1e290c7c7 Mon Sep 17 00:00:00 2001 From: James Shubin Date: Thu, 10 Jul 2014 20:06:41 -0400 Subject: Ensure that UUID directory is actually managed. This isn't necessary, but is more correct. I realized how I could do this, and have now implemented it. --- lib/facter/gluster_uuid.rb | 19 ++++++++++++++++--- manifests/host.pp | 25 +++++++++++++------------ 2 files changed, 29 insertions(+), 15 deletions(-) diff --git a/lib/facter/gluster_uuid.rb b/lib/facter/gluster_uuid.rb index ed0bf70..fa99a40 100644 --- a/lib/facter/gluster_uuid.rb +++ b/lib/facter/gluster_uuid.rb @@ -63,12 +63,25 @@ end # generate uuid and parent directory if they don't already exist... if not(module_vardir.nil?) and File.directory?(module_vardir) - if not File.directory?(uuiddir) - Dir::mkdir(uuiddir) + + create = false + if File.directory?(uuiddir) + + if File.exist?(uuidfile) + test = File.open(uuidfile, 'r').read.strip.downcase # read into str + # skip over uuid's of the wrong length or that don't match (security!!) + if test.length == 36 and regexp.match(test) + create = false + else + create = true + end + else + create = true + end end # create a uuid and store it in our vardir if it doesn't already exist! - if File.directory?(uuiddir) and (not File.exist?(uuidfile)) + if create result = system("/usr/bin/uuidgen > '" + uuidfile + "'") if not(result) # TODO: print warning diff --git a/manifests/host.pp b/manifests/host.pp index 91a0548..7f6efed 100644 --- a/manifests/host.pp +++ b/manifests/host.pp @@ -60,9 +60,9 @@ define gluster::host( # 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 + recurse => true, # recurse into directory + purge => true, # purge unmanaged files + force => true, # purge subdirs and links require => File["${vardir}/"], } @@ -70,15 +70,16 @@ define gluster::host( # sticks if we ever go back to using automatic uuids. this is # useful if a user wants to initially import uuids by picking # them manually, and then letting puppet take over afterwards - if "${uuid}" != '' { - file { "${vardir}/uuid/uuid": - content => "${uuid}\n", - owner => root, - group => root, - mode => 600, # might as well... - ensure => present, - require => File["${vardir}/uuid/"], - } + file { "${vardir}/uuid/uuid": + content => "${uuid}" ? { + '' => undef, + default => "${uuid}\n", + }, + owner => root, + group => root, + mode => 600, # might as well... + ensure => present, + require => File["${vardir}/uuid/"], } $valid_uuid = "${uuid}" ? { -- cgit