Ask Your Question

access default values from other modules

asked 2015-11-10 07:31:09 -0600

teleivo gravatar image

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 for documentation.
class openmrs (
  $db_host = 'localhost',
  $db_name = 'openmrs',
  $db_owner = 'openmrs',
  $db_owner_password = 'openmrs',
) {

  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    =>
    require       => [

I install tomcat in a separate tomcat profile. In the component module I need to set the attribute 'catalinabase' of tomcat::war to point to the existing tomcat instance and I also need access to the tomcatuser 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.
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2015-11-12 01:09:03 -0600

Cristian Falcas gravatar image

This is how we do it also.

Since at profile level we don't want to do any logic and want to declare only classes, all other resources necessary and ifs/cases are declared in classes named "conf_something".

We mostly push configuration from hiera. So classes that use the same value for some parameters are configured from hiera with a lot of interpolation. For example:

     --- variables---
  "foreman_proxy_port": 8444,
  "puppet_master_port": 8140,
  "abrt::libreport::ureport::url": "https://%{::puppetmaster}:%{hiera('foreman_proxy_port')}/abrt",
  "foreman_proxy::puppet_url": "https://%{::fqdn}:%{hiera('puppet_master_port')}",

But, in case of defines and other resources where we need the same value as some parameter from another module, we do access the variable directly. For this we need to be certain that that specific class was declared before our resource.

This keeps our code cleaner.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2015-11-10 07:31:09 -0600

Seen: 109 times

Last updated: Nov 12 '15