aboutsummaryrefslogtreecommitdiff
path: root/manifests
diff options
context:
space:
mode:
authorJerome Charaoui <jcharaoui@cmaisonneuve.qc.ca>2010-04-07 14:25:08 -0400
committerMicah Anderson <micah@riseup.net>2010-09-02 18:17:13 -0400
commitfcb2b08309e7ad18ee58283d754cb41b54fd79d1 (patch)
treec5142364f91ec9742a6b9024e32351ce8553cbe9 /manifests
parent9f336296301d595aa879f89331d9b720b3cf62a4 (diff)
downloadpuppet-common-fcb2b08309e7ad18ee58283d754cb41b54fd79d1.tar.gz
puppet-common-fcb2b08309e7ad18ee58283d754cb41b54fd79d1.tar.bz2
concatenated_file: update define to latest from David Schmitt's common module
Diffstat (limited to 'manifests')
-rw-r--r--manifests/defines/concatenated_file.pp51
1 files changed, 41 insertions, 10 deletions
diff --git a/manifests/defines/concatenated_file.pp b/manifests/defines/concatenated_file.pp
index b6f8fb8..d605219 100644
--- a/manifests/defines/concatenated_file.pp
+++ b/manifests/defines/concatenated_file.pp
@@ -4,14 +4,31 @@
# Copyright (C) 2007 David Schmitt <david@schmitt.edv-bus.at>
# See LICENSE for the full license granted to you.
+module_dir { "common/cf": }
+
# TODO:
# * create the directory in _part too
+# This resource collects file snippets from a directory ($dir) and concatenates
+# them in lexical order of their names into a new file ($name). This can be
+# used to collect information from disparate sources, when the target file
+# format doesn't allow includes.
+#
+# concatenated_file_part can be used to easily configure content for this.
+#
+# If no $dir is specified, the target name with '.d' appended will be used.
+#
+# The $dir is purged by puppet and will only contain explicitely configured
+# files. This can be overridden by defining the directory before the
+# concatenated_file.
+#
+# 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",
-# }
-# Use Exec["concat_$name"] as Semaphor
+# concatenated_file { "/etc/some.conf":
+# dir => "/etc/some.conf.d",
+# }
define concatenated_file (
# where the snippets are located
$dir = '',
@@ -19,18 +36,22 @@ define concatenated_file (
$header = '',
# a file with content to append
$footer = '',
+ # default permissions for the target file
$mode = 0644, $owner = root, $group = 0
)
{
$dir_real = $dir ? { '' => "${name}.d", default => $dir }
+ $tmp_file_name = regsubst($dir_real, '/', '_', 'G')
+ $tmp_file = "${module_dir_path}/${tmp_file_name}"
+
if defined(File[$dir_real]) {
debug("${dir_real} already defined")
} else {
file {
$dir_real:
- source => "puppet://$server/modules/common/empty",
+ source => "puppet:///modules/common/empty",
checksum => mtime,
ignore => '.ignore',
recurse => true, purge => true, force => true,
@@ -40,9 +61,18 @@ define concatenated_file (
}
file {
- $name:
+ $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 there is a header or footer file, add it
@@ -59,11 +89,11 @@ define concatenated_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} >| ${name}",
- refreshonly => true,
+ 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[$name],
- alias => [ "concat_${dir_real}"] ,
+ before => File[$tmp_file],
+ alias => [ "concat_${dir_real}"],
+ loglevel => info
}
#case $header {
#'': {}
@@ -94,3 +124,4 @@ define concatenated_file_part (
}
}
+