Skip to content

Instantly share code, notes, and snippets.

@rodjek
Created January 16, 2012 06:29
Show Gist options
  • Save rodjek/1619400 to your computer and use it in GitHub Desktop.
Save rodjek/1619400 to your computer and use it in GitHub Desktop.
augeas nrpe command editor
define nrpe::command($command, $ensure='present') {
Augeas {
context => '/files/etc/nrpe.cfg',
}
case $ensure {
absent,present: {}
default: {
fail("Invalid ensure value passed to Nrpe::Command[$name]")
}
}
if $ensure == 'present' {
augeas {
"create command ${name}":
changes => "set command[last() + 1]/${name} \"${command}\"",
onlyif => "match command[./${name}] size == 0";
"set command ${name} to '${command}'":
changes => "set command[./${name}]/${name} \"${command}\"",
onlyif => "match command[./${name}='${command}'] size == 0",
require => Augeas["create command ${name}"];
}
} else {
augeas { "removing nrpe command ${name}":
changes => "rm command[./${name}]",
onlyif => "match command[./${name}] size != 0",
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment