aboutsummaryrefslogtreecommitdiff
path: root/manifests/defines/concatenated_file.pp
diff options
context:
space:
mode:
Diffstat (limited to 'manifests/defines/concatenated_file.pp')
-rw-r--r--manifests/defines/concatenated_file.pp148
1 files changed, 78 insertions, 70 deletions
diff --git a/manifests/defines/concatenated_file.pp b/manifests/defines/concatenated_file.pp
index b85456c..fc2c7a3 100644
--- a/manifests/defines/concatenated_file.pp
+++ b/manifests/defines/concatenated_file.pp
@@ -24,94 +24,102 @@ module_dir { "common/cf": }
#
# Depend on File[$name] to change if and only if its contents change. Notify
# Exec["concat_${name}"] if you want to force an update.
-#
+#
# Usage:
# concatenated_file { "/etc/some.conf":
-# dir => "/etc/some.conf.d",
+# dir => "/etc/some.conf.d",
# }
define concatenated_file (
- # where the snippets are located
- $dir = '',
- # a file with content to prepend
- $header = '',
- # a file with content to append
- $footer = '',
- # default permissions for the target file
- $mode = 0644, $owner = root, $group = 0
- )
+ $ensure = 'present',
+ # where the snippets are located
+ $dir = '',
+ # a file with content to prepend
+ $header = '',
+ # a file with content to append
+ $footer = '',
+ # default permissions for the target file
+ $mode = 0644, $owner = root, $group = 0
+ )
{
+ include common::moduledir::common::cf
- $dir_real = $dir ? { '' => "${name}.d", default => $dir }
-
- $tmp_file_name = regsubst($dir_real, '/', '_', 'G')
- $tmp_file = "${module_dir_path}/${tmp_file_name}"
+ $dir_real = $dir ? { '' => "${name}.d", default => $dir }
- if defined(File[$dir_real]) {
- debug("${dir_real} already defined")
- } else {
- file {
- $dir_real:
- source => "puppet://$server/modules/common/empty",
- checksum => mtime,
- ignore => '.ignore',
- recurse => true, purge => true, force => true,
- mode => $mode, owner => $owner, group => $group,
- notify => Exec["concat_${name}"];
- }
- }
+ $tmp_file_name = regsubst($dir_real, '/', '_', 'G')
+ $tmp_file = "${common::moduledir::module_dir_path}/${tmp_file_name}"
- file {
- $tmp_file:
- ensure => present, checksum => md5,
- mode => $mode, owner => $owner, group => $group;
- # decouple the actual file from the generation process by using a
- # temporary file and puppet's source mechanism. This ensures that events
- # for notify/subscribe will only be generated when there is an actual
- # change.
- $name:
- ensure => present, checksum => md5,
- source => $tmp_file,
- mode => $mode, owner => $owner, group => $group,
- require => File[$tmp_file];
- }
+ if defined(File[$dir_real]) {
+ debug("${dir_real} already defined")
+ } else {
+ file {
+ $dir_real:
+ ensure => $ensure ? {
+ 'present' => directory,
+ default => $ensure
+ },
+ source => "puppet:///modules/common/empty",
+ checksum => mtime,
+ ignore => '.ignore',
+ recurse => true, purge => true, force => true,
+ mode => $mode, owner => $owner, group => $group,
+ notify => Exec["concat_${name}"];
+ }
+ }
- # if there is a header or footer file, add it
- $additional_cmd = $header ? {
- '' => $footer ? {
- '' => '',
- default => "| cat - '${footer}' "
- },
- default => $footer ? {
- '' => "| cat '${header}' - ",
- default => "| cat '${header}' - '${footer}' "
- }
- }
+ file {
+ $tmp_file:
+ ensure => $ensure, checksum => md5,
+ mode => $mode, owner => $owner, group => $group;
+ # decouple the actual file from the generation process by using a
+ # temporary file and puppet's source mechanism. This ensures that events
+ # for notify/subscribe will only be generated when there is an actual
+ # change.
+ $name:
+ ensure => $ensure, checksum => md5,
+ source => $tmp_file,
+ mode => $mode, owner => $owner, group => $group,
+ require => File[$tmp_file];
+ }
- # use >| to force clobbering the target file
- 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}",
- subscribe => [ File[$dir_real] ],
- before => File[$tmp_file],
- alias => [ "concat_${dir_real}"],
- loglevel => info
- }
+ if $ensure == 'present' {
+ # if there is a header or footer file, add it
+ $additional_cmd = $header ? {
+ '' => $footer ? {
+ '' => '',
+ default => "| cat - '${footer}' "
+ },
+ default => $footer ? {
+ '' => "| cat '${header}' - ",
+ default => "| cat '${header}' - '${footer}' "
+ }
+ }
+ # use >| to force clobbering the target file
+ 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}",
+ subscribe => [ File[$dir_real] ],
+ before => File[$tmp_file],
+ alias => [ "concat_${dir_real}"],
+ loglevel => info
+ }
+ }
}
# Add a snippet called $name to the concatenated_file at $dir.
# The file can be referenced as File["cf_part_${name}"]
define concatenated_file_part (
- $dir, $content = '', $ensure = present,
- $mode = 0644, $owner = root, $group = 0
- )
+ $dir, $content = '', $ensure = present,
+ $mode = 0644, $owner = root, $group = 0
+ )
{
- file { "${dir}/${name}":
- ensure => $ensure, content => $content,
- mode => $mode, owner => $owner, group => $group,
- alias => "cf_part_${name}",
- notify => Exec["concat_${dir}"],
- }
+ file { "${dir}/${name}":
+ ensure => $ensure, content => $content,
+ mode => $mode, owner => $owner, group => $group,
+ alias => "cf_part_${name}",
+ notify => Exec["concat_${dir}"],
+ }
}
+