I'm currently banging my head trying to find the "best way" to achieve this type of granularity for puppet: I have a server running memcached in testing environment and another one running for the production environment.
These servers run with different memcached options and I'm using monit to monitor and restart them if needed, monit is managed through puppet and it monitors memcached through a memcached.monitrc, pretty straightforward until so.
My problem is: I have a defined resource named "monit::monitor" which receives a name get a template for that resource, like
monit::monitor { 'memcached': }
This is the code for monit::monitor:
define monit::monitor($template_params = {}) {
file { "/etc/monit/monit.d/${name}.monitrc":
ensure => present,
content => template("monit/${name}.monitrc.erb"),
}
}
This will look for "memached.monitrc.erb" in the modules/monit/templates dir and print it out, but in that file I need to parameterize the memory parameter for memcached, if it runs in testing env it should be 64m, if in production, 3072m.
templates/memcached.monitrc.erb looks like this
check process memcached with pidfile /var/run/memcached0.pid
start program = "/usr/bin/memcached -d -p 11211 -U 11211 -u memcached -m <%= template_params['memory'] %> -t 4 -c 1024 -P /var/run/memcached/memcached0.pid"
stop program = "/bin/kill -9 `cat /var/run/memcached0.pid`; rm /var/run/memcached0.pid"
if failed host 127.0.0.1 port 11211 then restart
group cache
What I'm using now is that monit::monitor supports a hash for templates param, but that obfuscates the template usage so you need to look at the template to see which parameters it should receive and I think that there's a better solution for this...
Thanks for the attention and sorry if it sounded confused :P