I have been learning Puppet (as in, the last 24 hours) and have come up with the following module to install Tomcat. It works great, but I can't help but feel like this is not the most optimal way to do this - particularly around the name[1-4]
part and steps/dependencies. If a "Puppet Master" :) could take a look at what I am doing and suggest improvements, I would be most appreciative.
class tomcat {
####
# Tomcat
# Variables
$tomcatVersionedDir="/usr/local/apache-tomcat-6.0.29"
$tomcatDir="/usr/local/tomcat"
$tomcatBinDir="${tomcatDir}/bin"
$tomcatDaemonSrcDir="${tomcatBinDir}/commons-daemon-1.0.2-native-src"
# 1) Get the package
file { "/root/tomcat6.tgz":
ensure => "file",
source => "puppet://puppet/tomcat/tomcat6.tgz",
}
# 2) Untar the package
define tomcat_expand() {
exec { "/bin/tar xzf /root/tomcat6.tgz":
cwd => "/usr/local",
creates => $tomcatVersionedDir,
}
}
tomcat_expand { name1:
require => File["/root/tomcat6.tgz"],
}
# 3) Create the symlink
file { "${tomcatDir}":
ensure => $tomcatVersionedDir,
require => Tomcat_expand["name1"],
}
# 4) Daemon source expand
define tomcat_daemon_expand() {
exec { "/bin/tar xzf commons-daemon-native.tar.gz":
cwd => "${tomcatDir}/bin",
creates => "${tomcatDaemonSrcDir}",
}
}
tomcat_daemon_expand { name2:
require => File["${tomcatDir}"],
}
# 5) Configure daemon
define tomcat_daemon_config() {
exec { "./configure > puppet-config.out":
path => "/bin:/usr/bin:.",
cwd => "${tomcatDaemonSrcDir}/unix",
creates => "${tomcatDaemonSrcDir}/unix/puppet-config.out",
}
}
tomcat_daemon_config { name3:
require => Tomcat_daemon_expand["name2"],
}
# 6) Compile daemon
define tomcat_daemon_compile() {
exec { "make clean && make":
path => "/bin:/usr/bin:.",
cwd => "${tomcatDaemonSrcDir}/unix",
creates => "${tomcatDaemonSrcDir}/unix/jsvc",
}
}
tomcat_daemon_compile { name4:
require => Tomcat_daemon_config["name3"],
}
# 7) Copy jsvc to bin directory
file { "${tomcatBinDir}/jsvc":
source => "${tomcatDaemonSrcDir}/unix/jsvc",
require => Tomcat_daemon_compile["name4"],
}
}
Is this style OK?
Another thing... since this is doing things like unpacking code for one task, is there a good way to do clean up, while still maintaining the flow through the steps? For example, deleting the commons-daemon-1.0.2-native-src
directory after jsvc
has been copied to bin
?
It looks way too "procedural," IMO. You have to think in a "declarative" way. I would personally just create .rpm's or .deb's from those tarballs, and specify another repo to use so all you would have to do is something like this:
etc. Those multiple defines seem unnecessary as well, I'd go with just straight Exec clauses but with aliases for each Exec type.
Example:
Revisiting a very old thread for the sake of future visitors -- you can get tomcat6 rpms from http://www.jpackage.org/ and install from them (either straight from a repo mirror, or via your own local repo).
Not sure what the situation is like for debs though.