make the removal of line safer
This commit is contained in:
parent
75f88ffda0
commit
b4ce2e8769
1 changed files with 17 additions and 16 deletions
|
@ -4,9 +4,9 @@
|
||||||
|
|
||||||
# Usage:
|
# Usage:
|
||||||
# line { description:
|
# line { description:
|
||||||
# file => "filename",
|
# file => "filename",
|
||||||
# line => "content",
|
# line => "content",
|
||||||
# ensure => {absent,*present*}
|
# ensure => {absent,*present*}
|
||||||
# }
|
# }
|
||||||
#
|
#
|
||||||
# Example:
|
# Example:
|
||||||
|
@ -24,19 +24,20 @@
|
||||||
#
|
#
|
||||||
#
|
#
|
||||||
define line($file, $line, $ensure = 'present') {
|
define line($file, $line, $ensure = 'present') {
|
||||||
case $ensure {
|
case $ensure {
|
||||||
default : { err ( "unknown ensure value '${ensure}'" ) }
|
default : { err ( "unknown ensure value '${ensure}'" ) }
|
||||||
present: {
|
present: {
|
||||||
exec { "echo '${line}' >> '${file}'":
|
exec { "echo '${line}' >> '${file}'":
|
||||||
unless => "grep -qFx '${line}' '${file}'"
|
unless => "grep -qFx '${line}' '${file}'"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
absent: {
|
absent: {
|
||||||
exec { "perl -ni -e 'print if \$_ ne \"${line}\n\";' '${file}'":
|
$subst_line = regsubst($line,'(/|\.)','\\\1','G')
|
||||||
onlyif => "grep -qFx '${line}' '${file}'"
|
exec { "/bin/sed -i '/${subst_line}/d' '${file}'":
|
||||||
}
|
onlyif => "/bin/grep -qFx '${line}' '${file}'"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue