it explains that "modules that have configuration should be configurable in a single way and single place",
and I agree.
However, as configuration grows in complexity, this means that the entry point would have an enourmous list of parameters,
that need to be propagated down to its dependencies.
for instance, myapp takes a $jmxtrans_output, which it passes to tomcat, which it passes to jmxtrans::connection.
and if I have more dependencies like this one, myapp would not take 4 parameters, but far too many.
what is a proper way to inject $jmxtrans_output to jmxtrans::connection without requiring to declare it in myapp nor tomcat?
I could declare to do $jmxtrans_output a global variable, but that is ugly.
what if I have myapp1, and myapp2, which uses two differents $jmxtrans_output?
node 'mynode' {
$tomcat_conf = {
port => 8080,
jmx_port => 9200,
jmx_username => 'my_tomcat_jmx_username',
jmx_password => 'my_tomcat_jmx_password',
}
$jmxtrans_output = {
port => 2003,
username => 'my_graphite_username',
password => 'my_graphite_password',
}
class { myapp:
tomcat_conf => $tomcat_conf,
jmxtrans_output => $jmxtrans_output,
market => 'US',
products => ['p1', 'p2', 'p3']
}
}
class myapp($tomcat_conf, $jmxtrans_output, $market, $products) {
# it installs several packages, as tomcat, imagemagick... and configuration files...
class { tomcat:
tomcat_conf => $tomcat_conf,
jmxtrans_output => $jmxtrans_output,
}
# package { imagemagik: ensure => installed }
# ...
}
class tomcat($tomcat_conf, $jmxtrans_output) {
# package { tomcat: ensure => installed }
# config file, using $tomcat_conf.{hostname, port, jmx_port, jmx_username, jmx_password}
#...
$tomcat_jmx = {
host => $tomcat_conf[hostname],
port => $tomcat_conf[jmx_port],
username => $tomcat_conf[jmx_username],
password => $tomcat_conf[jmx_password],
}
jmxtrans::connection { $name:
input => $tomcat_jmx,
output => $jmxtrans_output,
template_source => "myapp/tomcat_jmxtrans.json.erb",
# require => Class[jmxtrans]
}
}
# todo: replace $template_source with $objects (the objects to be monitored, instead of passing a full template)
define jmxtrans::connection ($input, $output, $template_source) {
notify {"jmxtrans::connection::input: $input": }
notify {"jmxtrans::connection::output: $output": }
file { "/tmp/jmxtrans_${hostname}_${name}.json":
content => "template that uses \ninput_host: ${input[host]}\ninput_port: ${input[port]}\ninput_username: ${input[username]}\ninput_password: ${input[password]}\noutput_host: ${output[host]}\noutput_port: ${output[port]}\noutput_username: ${output[username]}\noutput_password: ${output[password]}\n",
# content => template(template_source),
}
}