diff options
-rw-r--r-- | files/functions/gsub.rb | 8 | ||||
-rwxr-xr-x | files/functions/split.rb | 7 | ||||
-rw-r--r-- | manifests/defines/concatenated_file.pp | 11 |
3 files changed, 24 insertions, 2 deletions
diff --git a/files/functions/gsub.rb b/files/functions/gsub.rb index 743a700..371820f 100644 --- a/files/functions/gsub.rb +++ b/files/functions/gsub.rb @@ -1,7 +1,13 @@ # generic gsub call module Puppet::Parser::Functions newfunction(:gsub, :type => :rvalue) do |args| - args[0].gsub(/#{args[1]}/, args[2]) + if args[0].is_a?(Array) + args[0].collect do |val| + val.gsub(/#{args[1]}/, args[2]) + end + else + args[0].gsub(/#{args[1]}/, args[2]) + end end end diff --git a/files/functions/split.rb b/files/functions/split.rb new file mode 100755 index 0000000..d08a40b --- /dev/null +++ b/files/functions/split.rb @@ -0,0 +1,7 @@ +# generic split call +module Puppet::Parser::Functions + newfunction(:split, :type => :rvalue) do |args| + args[0].split(/#{args[1]}/) + end +end + diff --git a/manifests/defines/concatenated_file.pp b/manifests/defines/concatenated_file.pp index e701469..865a1ee 100644 --- a/manifests/defines/concatenated_file.pp +++ b/manifests/defines/concatenated_file.pp @@ -36,7 +36,16 @@ define concatenated_file ( } # if there is a header or footer file, add it - $additional_cmd = "$header$footer" ? { '' => '', default => "| cat '${header}' - '${footer}' " } + $additional_cmd = "$header" ? { + '' => $footer ? { + '' => '', + default => "| cat - '${footer}' " + }, + default => $footer ? { + '' => "| cat '${header}' - ", + default => "| cat '${header}' - '${footer}' " + } + } # use >| to force clobbering the target file exec { "/usr/bin/find ${dir} -maxdepth 1 -type f ! -name '*puppettmp' -print0 | sort -z | xargs -0 cat ${header_cmd} >| ${name}.puppettmp": |