I just noticed some strange Puppet behaviour. Take a look at this:
class monitoring { define nrpe_command ( $ensure = present, $command, $target = "/etc/nagios/nrpe.d/$title.cfg" ) { file { $target : ensure => file, owner => root, group => root, mode => 0755, content => "command[$title]=$command\n", } } } class puppet { monitoring::nrpe_command {"restart_puppet": command => "/etc/init.d/puppet restart" } }
This is the resulting I’ve got:
testhost:/etc/nagios/nrpe.d# ls puppet.cfg testhost:/etc/nagios/nrpe.d# cat puppet.cfg command[restart_puppet]=/usr/local/bin/restart_puppet_safely.sh testhost:/etc/nagios/nrpe.d#
Somehow, puppet eats everything until the last underscore in the $title variable when using it in the file title, but not when using the variable as content for that file.
Any ideas?
Have you tried correctly namespacing everything and perhaps replacing $title with $name?
So the definition could be like “$target = “/etc/nagios/nrpe.d/$::name.cfg” “
Actually, I just tried your suggestion, but that didn’t work out. Maybe I should add that this is puppet 0.25.4. Ancient, I know, but no explanation why it should behave like this.
Have you tried escaping your variables?
$target = “/etc/nagios/nrpe.d/${title}.cfg”
content => “command[${title}]=${command}\n”,
Issue remains the same