module-common/manifests/defines/line.pp
Micah Anderson 63a16ad8c0 Merge remote branch 'immerda/master'
Conflicts:
	lib/puppet/parser/functions/gsub.rb
	lib/puppet/parser/functions/prefix_with.rb
	lib/puppet/parser/functions/sha1.rb
	lib/puppet/parser/functions/slash_escape.rb
	lib/puppet/parser/functions/substitute.rb
	manifests/classes/lsb_release.pp
	manifests/defines/concatenated_file.pp
	manifests/defines/config_file.pp
	manifests/defines/line.pp
	manifests/defines/module_dir.pp
	manifests/defines/module_file.pp
	manifests/defines/replace.pp
	manifests/init.pp
2010-09-02 19:04:29 -04:00

54 lines
1.6 KiB
Puppet

# common/manifests/defines/line.pp -- a trivial mechanism to ensure a line exists in a file
# Copyright (C) 2007 David Schmitt <david@schmitt.edv-bus.at>
# See LICENSE for the full license granted to you.
# Ensures that a specific line is present or absent in a file. This can
# be very brittle, since even small changes can throw this off.
#
# If the line is not present yet, it will be appended to the file.
#
# The name of the define is not used. Just keep it (globally) unique and
# descriptive.
#
# Use this only for very trivial stuff. Usually replacing the whole file
# is a more stable solution with less maintenance headaches afterwards.
#
# Usage:
# line {
# description:
# file => "filename",
# line => "content",
# ensure => {absent,*present*}
# }
#
# Example:
# The following ensures that the line "allow ^$munin_host$" exists in
# /etc/munin/munin-node.conf, and if there are any changes notify the
# service for a restart
#
# line {
# allow_munin_host:
# file => "/etc/munin/munin-node.conf",
# line => "allow ^$munin_host$",
# ensure => present,
# notify => Service[munin-node],
# require => Package[munin-node];
# }
define line($file, $line, $ensure = 'present') {
case $ensure {
default : { err ( "unknown ensure value '${ensure}'" ) }
present: {
exec { "echo '${line}' >> '${file}'":
unless => "grep -qFx '${line}' '${file}'"
}
}
absent: {
$subst_line = regsubst($line,'(/|\.)','\\\1','G')
exec { "sed -i '/${subst_line}/d' '${file}'":
onlyif => "grep -qFx '${line}' '${file}'"
}
}
}
}