enable possibility to set a concatenated file to absent
This commit is contained in:
parent
218c68752e
commit
f8d9e9fd83
1 changed files with 18 additions and 12 deletions
|
@ -28,6 +28,7 @@
|
||||||
# dir => "/etc/some.conf.d",
|
# dir => "/etc/some.conf.d",
|
||||||
# }
|
# }
|
||||||
define concatenated_file (
|
define concatenated_file (
|
||||||
|
$ensure = 'present',
|
||||||
# where the snippets are located
|
# where the snippets are located
|
||||||
$dir = '',
|
$dir = '',
|
||||||
# a file with content to prepend
|
# a file with content to prepend
|
||||||
|
@ -50,6 +51,10 @@ define concatenated_file (
|
||||||
} else {
|
} else {
|
||||||
file {
|
file {
|
||||||
$dir_real:
|
$dir_real:
|
||||||
|
ensure => $ensure ? {
|
||||||
|
'present' => directory,
|
||||||
|
default => $ensure
|
||||||
|
},
|
||||||
source => "puppet:///modules/common/empty",
|
source => "puppet:///modules/common/empty",
|
||||||
checksum => mtime,
|
checksum => mtime,
|
||||||
ignore => '.ignore',
|
ignore => '.ignore',
|
||||||
|
@ -61,40 +66,41 @@ define concatenated_file (
|
||||||
|
|
||||||
file {
|
file {
|
||||||
$tmp_file:
|
$tmp_file:
|
||||||
ensure => present, checksum => md5,
|
ensure => $ensure, checksum => md5,
|
||||||
mode => $mode, owner => $owner, group => $group;
|
mode => $mode, owner => $owner, group => $group;
|
||||||
# decouple the actual file from the generation process by using a
|
# decouple the actual file from the generation process by using a
|
||||||
# temporary file and puppet's source mechanism. This ensures that events
|
# temporary file and puppet's source mechanism. This ensures that events
|
||||||
# for notify/subscribe will only be generated when there is an actual
|
# for notify/subscribe will only be generated when there is an actual
|
||||||
# change.
|
# change.
|
||||||
$name:
|
$name:
|
||||||
ensure => present, checksum => md5,
|
ensure => $ensure, checksum => md5,
|
||||||
source => $tmp_file,
|
source => $tmp_file,
|
||||||
mode => $mode, owner => $owner, group => $group,
|
mode => $mode, owner => $owner, group => $group,
|
||||||
require => File[$tmp_file];
|
require => File[$tmp_file];
|
||||||
}
|
}
|
||||||
|
|
||||||
# if there is a header or footer file, add it
|
if $ensure == 'present' {
|
||||||
$additional_cmd = $header ? {
|
# if there is a header or footer file, add it
|
||||||
|
$additional_cmd = $header ? {
|
||||||
'' => $footer ? {
|
'' => $footer ? {
|
||||||
'' => '',
|
'' => '',
|
||||||
default => "| cat - '${footer}' "
|
default => "| cat - '${footer}' "
|
||||||
},
|
},
|
||||||
default => $footer ? {
|
default => $footer ? {
|
||||||
'' => "| cat '${header}' - ",
|
'' => "| cat '${header}' - ",
|
||||||
default => "| cat '${header}' - '${footer}' "
|
default => "| cat '${header}' - '${footer}' "
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
# use >| to force clobbering the target file
|
# use >| to force clobbering the target file
|
||||||
exec { "concat_${name}":
|
exec { "concat_${name}":
|
||||||
command => "/usr/bin/find ${dir_real} -maxdepth 1 -type f ! -name '*puppettmp' -print0 | sort -z | xargs -0 cat ${additional_cmd} >| ${tmp_file}",
|
command => "/usr/bin/find ${dir_real} -maxdepth 1 -type f ! -name '*puppettmp' -print0 | sort -z | xargs -0 cat ${additional_cmd} >| ${tmp_file}",
|
||||||
subscribe => [ File[$dir_real] ],
|
subscribe => [ File[$dir_real] ],
|
||||||
before => File[$tmp_file],
|
before => File[$tmp_file],
|
||||||
alias => [ "concat_${dir_real}"],
|
alias => [ "concat_${dir_real}"],
|
||||||
loglevel => info
|
loglevel => info
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue