Hello,
I fight with a tomcat module and try to ensure several tomcat instances:
node XY{
include tomcat
ensure_tomcats{
"tomcat1":
tc_name => "tomcat1",
tc_path => "/app/tomcat1/tomcat",
version => "7.0.53";
"tomcat2":
tc_name => "tomcat2",
tc_path => "/app/tomcat2/tomcat",
version => "7.0.53";
}
I guess that my module isn't best practice:
#cat tomcat/manifests/init.pp
define download($version=""){
file{"download apache-tomcat-$version":
path => "/usr/local/src/apache-tomcat-$version.tar.gz",
ensure => present,
owner => $tc_name,
group => app,
mode => "0755",
source => "puppet:///modules/tomcat/apache-tomcat-$version.tar.gz",
}
}
define ensure_tomcats($tc_name, $tc_path, $version) {
download{"receive $tc_name $version":
version => $version,
}
file{"$tc_path":
ensure => present,
owner => $tc_name,
group => "app",
recurse => true,
require => Exec["$tc_name install"],
}
exec{"$tc_name extract apache-tomcat-$version":
command => "/bin/tar xfz /usr/local/src/apache-tomcat-$version.tar.gz",
cwd => "/usr/local/src",
creates => "/usr/local/src/apache-tomcat-$version",
user => "root",
require => File["download apache-tomcat-$version"],
}
exec{"$tc_name install":
command => "/bin/cp -r /usr/local/src/apache-tomcat-$version $tc_path",
cwd => "/usr/local/src",
creates => "$tc_path",
user => "root",
require => [ Exec["$tc_name extract apache-tomcat-$version"], ],
}
file{"$tc_path/webapps/examples":
ensure => absent,
force => true,
require => Exec["$tc_name install"],
}
file{"$tc_path/webapps/docs":
ensure => absent,
force => true,
require => Exec["$tc_name install"],
}
file{"/app/para/$tc_name.para":
ensure => present,
owner => "root",
group => "app",
mode => "0644",
source => [ "puppet:///modules/tomcat/$tc_name.para.$::hostname", "puppet:///modules/tomcat/$tc_name.para" ],
}
user{"$tc_name":
ensure => present,
home => $tc_path,
managehome => true,
groups => "app",
}
file{"tomcat-users $tc_name":
ensure => file,
path => "${tc_path}/conf/tomcat-users.xml",
owner => $tc_name,
group => "app",
source => [
"puppet:///modules/tomcat/$::hostname.tomcat-users.xml",
"puppet:///modules/tomcat/tomcat-users.xml",
],
require => Exec["$tc_name install"],
}
file{"server.xml $tc_name":
ensure => file,
path => "${tc_path}/conf/server.xml",
owner => $tc_name,
group => "app",
source => [
"puppet:///modules/tomcat/$::hostname.$tc_name.server.xml",
"puppet:///modules/tomcat/$tc_name.server.xml",
"puppet:///modules/tomcat/server.xml",
],
notify => Service["$tc_name"],
require => Exec["$tc_name install"],
}
file{"manager web.xml $tc_name":
ensure => file,
path => "${tc_path}/webapps/manager/WEB-INF/web.xml",
owner => $tc_name,
group => "app",
source => [
"puppet:///modules/tomcat/$::hostname.$tc_name.manager.web.xml",
"puppet:///modules/tomcat/$::hostname.manager.web.xml",
"puppet:///modules/tomcat/manager.web.xml",
],
notify => Service["$tc_name"],
require => Exec["$tc_name install"],
}
file{"setenv.sh $tc_name":
ensure => file,
path => "${tc_path}/bin/setenv.sh",
owner => $tc_name,
group => "app",
mode => "0750",
source => [
"puppet:///modules/tomcat/$::hostname.$
tc_name.setenv.sh",
"puppet:///modules/tomcat/$::
hostname.setenv.sh",
"puppet:///modules/tomcat/setenv.sh",
],
require => Exec["$tc_name install"],
}
file {"/etc/init.d/$tc_name":
content => template('tomcat/tomcat_init.erb'),
owner => root,
group => root,
mode => 0755,
}
service{"$tc_name":
ensure => running,
enable => true,
hasrestart => true,
require => [ File["$tc_path"], File["setenv.sh $tc_name"], File["manager web.xml $tc_name"], File["server.xml $tc_name"], File["/etc/init.d/$tc_name"], ],
}
}
class tomcat{
file{'/app/proc/tomcat':
ensure => present,
owner => "root",
group => "app",
mode => "0750",
source => "puppet:///modules/tomcat/tomcat",
}
}
My problem is that if there're two tomcat instances with the same version the module try to download the apache-tomcat tarball every time.
Error: Could not retrieve catalog from remote server: Error 400 on SERVER: Duplicate declaration: File[download apache-tomcat-7.0.53] is already declared in file /etc/puppet/modules/tomcat/manifests/init.pp:9; cannot redeclare at /etc/puppet/modules/tomcat/manifests/init.pp:9 on node YX
Thanks in advance
Björn