Hi All,
I'm trying to write a module which unpacks an archive to a specified
location, the idea is as follows:
Let's say I'm trying to deploy an archive of grails-1.3.7
1. Check that a directory exists at $targetDir/grails-1.3.7
2. If it does, do nothing
3. If it doesn't then do the following...
4. Copy grails-1.3.7.zip from the module source to $targetDir
5. Unpack to $targetDir/grails-1.3.7
6. Delete the archive so we don't end up with mess in our directories
I have this *mostly* working, i.e. the code below performs all of the steps
above successfully, but for some reason I cannot stop steps 4 and onwards
from happening every time Puppet applies the manifests, irrespective of
whether the $targetDir/grails-1.3.7 directory already exists.
Here's the code
*Module code:* modules/archive/unpack.pp
define archive::unpack($archiveName,
$appName,
$archiveDir,
$targetDir,
$pathFolder,
$owner = "root",
$group = "root",
$mode = "644") {
#Set the extraction command appropriately based on the archive type.
$command = $archiveName ? {
/(^.*\.tar\.gz$)|(^.*\.tgz$)/ => "/bin/tar zxf $targetDir/$archiveName",
/(^.*\.tar$)/ => "/bin/tar xf $targetDir/$archiveName",
/^.*\.zip$/ => "/usr/bin/unzip $targetDir/$archiveName",
default => "Error: Could not detect archive type from archive name
($archiveName), cannot unpack. Supported types: .tar.gzip, .zip",
}
# Check if the unpacked archive directory exists
# the idea here was to have all subsequent actions
# subscribe to the outcome of this check so that the archive
# would only be copied, unpacked, chowned and chmodded if
# the directory specified by this exec did not exist. This doesn't seem
# to work though since "copy_archive_$name" always seems to be invoked
# irrespective of the outcome of the onlyif condition in this exec.
exec { "check_unpacked_archive_exists_$name":
command => "/bin/echo '$targetDir/$appName does not exist, it will be
created.'",
cwd => $targetDir,
creates => "$targetDir/$appName",
onlyif => "/usr/bin/test ! -d $targetDir/$appName",
logoutput => true,
}
# copy file from puppet master to local system
file { "copy_archive_$name":
path => "$targetDir/$archiveName",
source => "$archiveDir/$archiveName",
replace => false,
subscribe => Exec["check_unpacked_archive_exists_$name"],
}
# extract local file
exec { "unpack_archive_$name":
command => $command,
cwd => $targetDir,
creates => "$targetDir/$appName",
refreshonly => true,
logoutput => true,
subscribe => File["copy_archive_$name"],
}
# delete copied archive
exec { "delete_copied_archive_$name":
command => "/bin/rm -f $targetDir/$archiveName",
cwd => "$targetDir",
subscribe => Exec["unpack_archive_$name"],
logoutput => true,
}
}
*Invocation code:*
class grails {
$appName = "grails-2.0.0.M1"
$archiveName = "$appName.zip"
$archiveDir = "puppet:///modules/grails"
$targetDir = "/usr/local/java"
$pathFolder = "bin"
$owner = root
$group = dev
$mode = 6775
archive::unpack { "install_$appName":
archiveName => $archiveName,
appName => $appName,
archiveDir => $archiveDir,
targetDir => $targetDir,
pathFolder => $pathFolder,
owner => $owner,
group => $group,
mode => $mode,
}
}
The frustrating thing is that the exec called "*
check_unpacked_archive_exists_$name*" is definitely only firing when it
finds the sought folder to be missing, which is what I want it to do. What
I don't understand is why the file called "*copy_archive_$name*" which
subscribes to that exec gets fired everytime. I can't help but think that
this would be made much much easier if only the *file* resource supported '*
onlyif*'... but while it doesn't does anyone have any insight as to why I'm
seeing this issue?
Cheers,
Edd
--
Web: http://www.eddgrant.com
Email: [email protected]
Mobile: +44 (0) 7861 394 543
--
You received this message because you are subscribed to the Google Groups
"Puppet Users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/puppet-users?hl=en.