I have a java application for which I wrote a component module (see code below) that deploys a war file on tomcat using the forge module puppetlabs/tomcat
# Class: openmrs: See README.md for documentation.
class openmrs (
$tomcat_catalina_base,
$tomcat_user,
$openmrs_application_data_directory,
$db_host = 'localhost',
$db_name = 'openmrs',
$db_owner = 'openmrs',
$db_owner_password = 'openmrs',
) {
validate_absolute_path($tomcat_catalina_base)
validate_string($tomcat_user)
validate_absolute_path($openmrs_application_data_directory)
validate_string($db_host)
validate_string($db_name)
validate_string($db_owner)
validate_string($db_owner_password)
include '::tomcat'
file { $openmrs_application_data_directory:
ensure => 'directory',
owner => $tomcat_user,
group => $tomcat_user,
mode => '0755',
}
mysql::db { $db_name:
user => $db_owner,
password => $db_owner_password,
host => $db_host,
grant => ['ALL'],
}
tomcat::war { 'openmrs.war':
catalina_base => $tomcat_catalina_base,
war_source =>
'http://sourceforge.net/projects/openmrs/files/releases/OpenMRS_Platform_1.11.4/openmrs.war',
require => [
File[$openmrs_application_data_directory],
Mysql::Db[$db_name],
]
}
}
I install tomcat in a separate tomcat profile. In the component module I need to set the attribute 'catalina_base' of tomcat::war to point to the existing tomcat instance and I also need access to the tomcat_user to create a file that is readable by the tomcat user. I therefore pass these 2 variables as required parameters into my module.
I just wonder about the best practice here:
- Is it ok to have a component module that has required parameters, since there are no sane defaults for some parameters (like in my case for tomcat user/base folder)?
- I assume it is bad practice to access variables directly from another module like '::tomcat' in a component module to get default values from there?
- When would you write a component module? In my case I could also just move my module code up to a profile which installs/configures tomcat with puppetlabs/tomcat and deploys the war file.
↧