From 69a63c5767ad27a33e4b86b8c8f2b58cc8f7da7d Mon Sep 17 00:00:00 2001 From: mh Date: Thu, 28 Aug 2008 10:21:38 +0000 Subject: fixed quoting --- manifests/init.pp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/manifests/init.pp b/manifests/init.pp index be94ab8..069ff4c 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -7,8 +7,8 @@ file { # module-local data, e.g. for constructing config files "/var/lib/puppet/modules": ensure => directory, - source => "puppet:///common/modules/", - ignore => ".ignore", + source => "puppet://$server/common/modules/", + ignore => '\.ignore', recurse => true, purge => true, force => true, mode => 0755, owner => root, group => 0; } -- cgit v1.2.3 From 49b127b80a2248a1f5fb4bed1e0c0685583d6746 Mon Sep 17 00:00:00 2001 From: mh Date: Sat, 25 Oct 2008 21:25:06 +0000 Subject: we don't require any of these execs, so we don't need them --- manifests/classes/lsb_release.pp | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/manifests/classes/lsb_release.pp b/manifests/classes/lsb_release.pp index 8455a56..73a9114 100644 --- a/manifests/classes/lsb_release.pp +++ b/manifests/classes/lsb_release.pp @@ -19,7 +19,6 @@ class assert_lsbdistcodename { case $lsbdistcodename { '': { err("Please install lsb_release or set facter_lsbdistcodename in the environment of $fqdn") - exec { "false # assert_lsbdistcodename": alias => assert_lsbdistcodename } } 'n/a': { case $operatingsystem { @@ -32,15 +31,9 @@ class assert_lsbdistcodename { } exec { "false # assert_lsbdistcodename": alias => assert_lsbdistcodename } } - default: { - exec { "true # assert_lsbdistcodename": alias => assert_lsbdistcodename } - exec { "true # require_lsbdistcodename": alias => require_lsbdistcodename } - } } } # To fail the complete compilation, include this class -class require_lsbdistcodename inherits assert_lsbdistcodename { - exec { "false # require_lsbdistcodename": require => Exec[require_lsbdistcodename], } -} +class require_lsbdistcodename inherits assert_lsbdistcodename {} -- cgit v1.2.3 From 61d767b56155650df65397ef326be28c2f35956f Mon Sep 17 00:00:00 2001 From: mh Date: Thu, 30 Apr 2009 13:40:43 +0000 Subject: added a strlength function to get the length of a string into puppet --- plugins/puppet/parser/functions/strlength.rb | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 plugins/puppet/parser/functions/strlength.rb diff --git a/plugins/puppet/parser/functions/strlength.rb b/plugins/puppet/parser/functions/strlength.rb new file mode 100644 index 0000000..3b99ed0 --- /dev/null +++ b/plugins/puppet/parser/functions/strlength.rb @@ -0,0 +1,6 @@ +module Puppet::Parser::Functions + newfunction(:strlength, :type => :rvalue) do |args| + argv[0].to_s.length + end +end + -- cgit v1.2.3 From 91ea4d11ae7ae450b17ae5d35c1539abe7f35fb9 Mon Sep 17 00:00:00 2001 From: mh Date: Thu, 30 Apr 2009 17:43:09 +0000 Subject: fixing typo --- plugins/puppet/parser/functions/strlength.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/puppet/parser/functions/strlength.rb b/plugins/puppet/parser/functions/strlength.rb index 3b99ed0..8f93e4e 100644 --- a/plugins/puppet/parser/functions/strlength.rb +++ b/plugins/puppet/parser/functions/strlength.rb @@ -1,6 +1,6 @@ module Puppet::Parser::Functions newfunction(:strlength, :type => :rvalue) do |args| - argv[0].to_s.length + args[0].to_s.length end end -- cgit v1.2.3 From 37b37ae82fbc2867ac759e627f53c5e6a8be687a Mon Sep 17 00:00:00 2001 From: mh Date: Wed, 10 Jun 2009 20:00:31 +0200 Subject: whitespace --- plugins/puppet/parser/functions/strlength.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/puppet/parser/functions/strlength.rb b/plugins/puppet/parser/functions/strlength.rb index 8f93e4e..147b24a 100644 --- a/plugins/puppet/parser/functions/strlength.rb +++ b/plugins/puppet/parser/functions/strlength.rb @@ -1,6 +1,6 @@ module Puppet::Parser::Functions newfunction(:strlength, :type => :rvalue) do |args| - args[0].to_s.length + args[0].to_s.length end end -- cgit v1.2.3 From 97e15ea5a84bf414529e110a4215d9fe7f9f20e0 Mon Sep 17 00:00:00 2001 From: mh Date: Sat, 31 Oct 2009 15:16:37 +0100 Subject: move plugin directory to fit new 0.25 style --- lib/puppet/parser/functions/basename.rb | 16 ++++++++++ lib/puppet/parser/functions/dirname.rb | 16 ++++++++++ lib/puppet/parser/functions/gsub.rb | 17 +++++++++++ lib/puppet/parser/functions/hostname.rb | 13 +++++++++ lib/puppet/parser/functions/prefix_with.rb | 9 ++++++ lib/puppet/parser/functions/re_escape.rb | 7 +++++ lib/puppet/parser/functions/sha1.rb | 9 ++++++ lib/puppet/parser/functions/slash_escape.rb | 7 +++++ lib/puppet/parser/functions/split.rb | 17 +++++++++++ lib/puppet/parser/functions/strlength.rb | 6 ++++ lib/puppet/parser/functions/substitute.rb | 20 +++++++++++++ manifests/classes/lsb_release.pp | 39 ------------------------- plugins/puppet/parser/functions/basename.rb | 16 ---------- plugins/puppet/parser/functions/dirname.rb | 16 ---------- plugins/puppet/parser/functions/gsub.rb | 17 ----------- plugins/puppet/parser/functions/prefix_with.rb | 9 ------ plugins/puppet/parser/functions/re_escape.rb | 7 ----- plugins/puppet/parser/functions/sha1.rb | 9 ------ plugins/puppet/parser/functions/slash_escape.rb | 7 ----- plugins/puppet/parser/functions/split.rb | 17 ----------- plugins/puppet/parser/functions/strlength.rb | 6 ---- plugins/puppet/parser/functions/substitute.rb | 20 ------------- 22 files changed, 137 insertions(+), 163 deletions(-) create mode 100644 lib/puppet/parser/functions/basename.rb create mode 100644 lib/puppet/parser/functions/dirname.rb create mode 100644 lib/puppet/parser/functions/gsub.rb create mode 100644 lib/puppet/parser/functions/hostname.rb create mode 100644 lib/puppet/parser/functions/prefix_with.rb create mode 100644 lib/puppet/parser/functions/re_escape.rb create mode 100644 lib/puppet/parser/functions/sha1.rb create mode 100644 lib/puppet/parser/functions/slash_escape.rb create mode 100644 lib/puppet/parser/functions/split.rb create mode 100644 lib/puppet/parser/functions/strlength.rb create mode 100644 lib/puppet/parser/functions/substitute.rb delete mode 100644 manifests/classes/lsb_release.pp delete mode 100644 plugins/puppet/parser/functions/basename.rb delete mode 100644 plugins/puppet/parser/functions/dirname.rb delete mode 100644 plugins/puppet/parser/functions/gsub.rb delete mode 100644 plugins/puppet/parser/functions/prefix_with.rb delete mode 100644 plugins/puppet/parser/functions/re_escape.rb delete mode 100644 plugins/puppet/parser/functions/sha1.rb delete mode 100644 plugins/puppet/parser/functions/slash_escape.rb delete mode 100644 plugins/puppet/parser/functions/split.rb delete mode 100644 plugins/puppet/parser/functions/strlength.rb delete mode 100644 plugins/puppet/parser/functions/substitute.rb diff --git a/lib/puppet/parser/functions/basename.rb b/lib/puppet/parser/functions/basename.rb new file mode 100644 index 0000000..226d6e5 --- /dev/null +++ b/lib/puppet/parser/functions/basename.rb @@ -0,0 +1,16 @@ +# basename(string) : string +# basename(string[]) : string[] +# +# Returns the last component of the filename given as argument, which must be +# formed using forward slashes (``/..) regardless of the separator used on the +# local file system. +module Puppet::Parser::Functions + newfunction(:basename, :type => :rvalue) do |args| + if args[0].is_a?(Array) + args.collect do |a| File.basename(a) end + else + File.basename(args[0]) + end + end +end + diff --git a/lib/puppet/parser/functions/dirname.rb b/lib/puppet/parser/functions/dirname.rb new file mode 100644 index 0000000..44b4a00 --- /dev/null +++ b/lib/puppet/parser/functions/dirname.rb @@ -0,0 +1,16 @@ +# dirname(string) : string +# dirname(string[]) : string[] +# +# Returns all components of the filename given as argument except the last +# one. The filename must be formed using forward slashes (``/..) regardless of +# the separator used on the local file system. +module Puppet::Parser::Functions + newfunction(:dirname, :type => :rvalue) do |args| + if args[0].is_a?(Array) + args.collect do |a| File.dirname(a) end + else + File.dirname(args[0]) + end + end +end + diff --git a/lib/puppet/parser/functions/gsub.rb b/lib/puppet/parser/functions/gsub.rb new file mode 100644 index 0000000..e2410ff --- /dev/null +++ b/lib/puppet/parser/functions/gsub.rb @@ -0,0 +1,17 @@ +module Puppet::Parser::Functions + # thin wrapper around the ruby gsub function + # gsub($string, $pattern, $replacement) will replace all occurrences of + # $pattern in $string with $replacement. $string can be either a singel + # value or an array. In the latter case, each element of the array will + # be processed in turn. + newfunction(:gsub, :type => :rvalue) do |args| + 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/lib/puppet/parser/functions/hostname.rb b/lib/puppet/parser/functions/hostname.rb new file mode 100644 index 0000000..7bc477f --- /dev/null +++ b/lib/puppet/parser/functions/hostname.rb @@ -0,0 +1,13 @@ +# get an uniq array of ipaddresses for a hostname +require 'resolv' + +module Puppet::Parser::Functions + newfunction(:hostname, :type => :rvalue) do |args| + res = Array.new + Resolv::DNS.new.each_address(args[0]){ |addr| + res << addr + } + res.uniq + end +end + diff --git a/lib/puppet/parser/functions/prefix_with.rb b/lib/puppet/parser/functions/prefix_with.rb new file mode 100644 index 0000000..6e64a4a --- /dev/null +++ b/lib/puppet/parser/functions/prefix_with.rb @@ -0,0 +1,9 @@ +# prefix arguments 2..n with first argument + +module Puppet::Parser::Functions + newfunction(:prefix_with, :type => :rvalue) do |args| + prefix = args.shift + args.collect {|v| "%s%s" % [prefix, v] } + end +end + diff --git a/lib/puppet/parser/functions/re_escape.rb b/lib/puppet/parser/functions/re_escape.rb new file mode 100644 index 0000000..6e5904b --- /dev/null +++ b/lib/puppet/parser/functions/re_escape.rb @@ -0,0 +1,7 @@ +# apply regexp escaping to a string +module Puppet::Parser::Functions + newfunction(:re_escape, :type => :rvalue) do |args| + Regexp.escape(args[0]) + end +end + diff --git a/lib/puppet/parser/functions/sha1.rb b/lib/puppet/parser/functions/sha1.rb new file mode 100644 index 0000000..b5aa813 --- /dev/null +++ b/lib/puppet/parser/functions/sha1.rb @@ -0,0 +1,9 @@ +# return the sha1 hash +require 'digest/sha1' + +module Puppet::Parser::Functions + newfunction(:sha1, :type => :rvalue) do |args| + Digest::SHA1.hexdigest(args[0]) + end +end + diff --git a/lib/puppet/parser/functions/slash_escape.rb b/lib/puppet/parser/functions/slash_escape.rb new file mode 100644 index 0000000..04d3b95 --- /dev/null +++ b/lib/puppet/parser/functions/slash_escape.rb @@ -0,0 +1,7 @@ +# escape slashes in a String +module Puppet::Parser::Functions + newfunction(:slash_escape, :type => :rvalue) do |args| + args[0].gsub(/\//, '\\/') + end +end + diff --git a/lib/puppet/parser/functions/split.rb b/lib/puppet/parser/functions/split.rb new file mode 100644 index 0000000..5237c92 --- /dev/null +++ b/lib/puppet/parser/functions/split.rb @@ -0,0 +1,17 @@ +# split($string, $delimiter) : $string +# split($string[], $delimiter) : $string[][] +# +# Split the first argument(s) on every $delimiter. $delimiter is interpreted as +# Ruby regular expression. +# +# For long-term portability it is recommended to refrain from using Ruby's +# extended RE features. +module Puppet::Parser::Functions + newfunction(:split, :type => :rvalue) do |args| + if args[0].is_a?(Array) + args.collect do |a| a.split(/#{args[1]}/) end + else + args[0].split(/#{args[1]}/) + end + end +end diff --git a/lib/puppet/parser/functions/strlength.rb b/lib/puppet/parser/functions/strlength.rb new file mode 100644 index 0000000..147b24a --- /dev/null +++ b/lib/puppet/parser/functions/strlength.rb @@ -0,0 +1,6 @@ +module Puppet::Parser::Functions + newfunction(:strlength, :type => :rvalue) do |args| + args[0].to_s.length + end +end + diff --git a/lib/puppet/parser/functions/substitute.rb b/lib/puppet/parser/functions/substitute.rb new file mode 100644 index 0000000..4c97def --- /dev/null +++ b/lib/puppet/parser/functions/substitute.rb @@ -0,0 +1,20 @@ +# subsititute($string, $regex, $replacement) : $string +# subsititute($string[], $regex, $replacement) : $string[] +# +# Replace all ocurrences of $regex in $string by $replacement. +# $regex is interpreted as Ruby regular expression. +# +# For long-term portability it is recommended to refrain from using Ruby's +# extended RE features. +module Puppet::Parser::Functions + newfunction(:substitute, :type => :rvalue) do |args| + 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/manifests/classes/lsb_release.pp b/manifests/classes/lsb_release.pp deleted file mode 100644 index 73a9114..0000000 --- a/manifests/classes/lsb_release.pp +++ /dev/null @@ -1,39 +0,0 @@ -# common/manifests/classes/lsb_release.pp -- request the installation of -# lsb_release to get to lsbdistcodename, which is used throughout the manifests -# -# Copyright (C) 2007 David Schmitt -# See LICENSE for the full license granted to you. - -# Changelog: -# 2007-08-26: micah reported, that lsb_release can report -# nonsensical values for lsbdistcodename; assert_lsbdistcodename now -# recognises "n/a" and acts accordingly - -# This lightweight class only asserts that $lsbdistcodename is set. -# If the assertion fails, an error is printed on the server -# -# To fail individual resources on a missing lsbdistcodename, require -# Exec[assert_lsbdistcodename] on the specific resource -class assert_lsbdistcodename { - - case $lsbdistcodename { - '': { - err("Please install lsb_release or set facter_lsbdistcodename in the environment of $fqdn") - } - 'n/a': { - case $operatingsystem { - "Debian": { - err("lsb_release was unable to report your distcodename; This seems to indicate a broken apt/sources.list on $fqdn") - } - default: { - err("lsb_release was unable to report your distcodename; please set facter_lsbdistcodename in the environment of $fqdn") - } - } - exec { "false # assert_lsbdistcodename": alias => assert_lsbdistcodename } - } - } - -} - -# To fail the complete compilation, include this class -class require_lsbdistcodename inherits assert_lsbdistcodename {} diff --git a/plugins/puppet/parser/functions/basename.rb b/plugins/puppet/parser/functions/basename.rb deleted file mode 100644 index 226d6e5..0000000 --- a/plugins/puppet/parser/functions/basename.rb +++ /dev/null @@ -1,16 +0,0 @@ -# basename(string) : string -# basename(string[]) : string[] -# -# Returns the last component of the filename given as argument, which must be -# formed using forward slashes (``/..) regardless of the separator used on the -# local file system. -module Puppet::Parser::Functions - newfunction(:basename, :type => :rvalue) do |args| - if args[0].is_a?(Array) - args.collect do |a| File.basename(a) end - else - File.basename(args[0]) - end - end -end - diff --git a/plugins/puppet/parser/functions/dirname.rb b/plugins/puppet/parser/functions/dirname.rb deleted file mode 100644 index 44b4a00..0000000 --- a/plugins/puppet/parser/functions/dirname.rb +++ /dev/null @@ -1,16 +0,0 @@ -# dirname(string) : string -# dirname(string[]) : string[] -# -# Returns all components of the filename given as argument except the last -# one. The filename must be formed using forward slashes (``/..) regardless of -# the separator used on the local file system. -module Puppet::Parser::Functions - newfunction(:dirname, :type => :rvalue) do |args| - if args[0].is_a?(Array) - args.collect do |a| File.dirname(a) end - else - File.dirname(args[0]) - end - end -end - diff --git a/plugins/puppet/parser/functions/gsub.rb b/plugins/puppet/parser/functions/gsub.rb deleted file mode 100644 index e2410ff..0000000 --- a/plugins/puppet/parser/functions/gsub.rb +++ /dev/null @@ -1,17 +0,0 @@ -module Puppet::Parser::Functions - # thin wrapper around the ruby gsub function - # gsub($string, $pattern, $replacement) will replace all occurrences of - # $pattern in $string with $replacement. $string can be either a singel - # value or an array. In the latter case, each element of the array will - # be processed in turn. - newfunction(:gsub, :type => :rvalue) do |args| - 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/plugins/puppet/parser/functions/prefix_with.rb b/plugins/puppet/parser/functions/prefix_with.rb deleted file mode 100644 index 6e64a4a..0000000 --- a/plugins/puppet/parser/functions/prefix_with.rb +++ /dev/null @@ -1,9 +0,0 @@ -# prefix arguments 2..n with first argument - -module Puppet::Parser::Functions - newfunction(:prefix_with, :type => :rvalue) do |args| - prefix = args.shift - args.collect {|v| "%s%s" % [prefix, v] } - end -end - diff --git a/plugins/puppet/parser/functions/re_escape.rb b/plugins/puppet/parser/functions/re_escape.rb deleted file mode 100644 index 6e5904b..0000000 --- a/plugins/puppet/parser/functions/re_escape.rb +++ /dev/null @@ -1,7 +0,0 @@ -# apply regexp escaping to a string -module Puppet::Parser::Functions - newfunction(:re_escape, :type => :rvalue) do |args| - Regexp.escape(args[0]) - end -end - diff --git a/plugins/puppet/parser/functions/sha1.rb b/plugins/puppet/parser/functions/sha1.rb deleted file mode 100644 index b5aa813..0000000 --- a/plugins/puppet/parser/functions/sha1.rb +++ /dev/null @@ -1,9 +0,0 @@ -# return the sha1 hash -require 'digest/sha1' - -module Puppet::Parser::Functions - newfunction(:sha1, :type => :rvalue) do |args| - Digest::SHA1.hexdigest(args[0]) - end -end - diff --git a/plugins/puppet/parser/functions/slash_escape.rb b/plugins/puppet/parser/functions/slash_escape.rb deleted file mode 100644 index 04d3b95..0000000 --- a/plugins/puppet/parser/functions/slash_escape.rb +++ /dev/null @@ -1,7 +0,0 @@ -# escape slashes in a String -module Puppet::Parser::Functions - newfunction(:slash_escape, :type => :rvalue) do |args| - args[0].gsub(/\//, '\\/') - end -end - diff --git a/plugins/puppet/parser/functions/split.rb b/plugins/puppet/parser/functions/split.rb deleted file mode 100644 index 5237c92..0000000 --- a/plugins/puppet/parser/functions/split.rb +++ /dev/null @@ -1,17 +0,0 @@ -# split($string, $delimiter) : $string -# split($string[], $delimiter) : $string[][] -# -# Split the first argument(s) on every $delimiter. $delimiter is interpreted as -# Ruby regular expression. -# -# For long-term portability it is recommended to refrain from using Ruby's -# extended RE features. -module Puppet::Parser::Functions - newfunction(:split, :type => :rvalue) do |args| - if args[0].is_a?(Array) - args.collect do |a| a.split(/#{args[1]}/) end - else - args[0].split(/#{args[1]}/) - end - end -end diff --git a/plugins/puppet/parser/functions/strlength.rb b/plugins/puppet/parser/functions/strlength.rb deleted file mode 100644 index 147b24a..0000000 --- a/plugins/puppet/parser/functions/strlength.rb +++ /dev/null @@ -1,6 +0,0 @@ -module Puppet::Parser::Functions - newfunction(:strlength, :type => :rvalue) do |args| - args[0].to_s.length - end -end - diff --git a/plugins/puppet/parser/functions/substitute.rb b/plugins/puppet/parser/functions/substitute.rb deleted file mode 100644 index 4c97def..0000000 --- a/plugins/puppet/parser/functions/substitute.rb +++ /dev/null @@ -1,20 +0,0 @@ -# subsititute($string, $regex, $replacement) : $string -# subsititute($string[], $regex, $replacement) : $string[] -# -# Replace all ocurrences of $regex in $string by $replacement. -# $regex is interpreted as Ruby regular expression. -# -# For long-term portability it is recommended to refrain from using Ruby's -# extended RE features. -module Puppet::Parser::Functions - newfunction(:substitute, :type => :rvalue) do |args| - 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 - -- cgit v1.2.3 From 36c3eecba32ef791f355df369c96d757ad096fe6 Mon Sep 17 00:00:00 2001 From: mh Date: Sat, 31 Oct 2009 15:26:59 +0100 Subject: remove unnecessary import --- manifests/init.pp | 1 - 1 file changed, 1 deletion(-) diff --git a/manifests/init.pp b/manifests/init.pp index 069ff4c..f01ba24 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -14,4 +14,3 @@ file { } import "defines/*.pp" -import "classes/*.pp" -- cgit v1.2.3 From d75dcc86f862b2fa5b7b72c2958915b4b029c465 Mon Sep 17 00:00:00 2001 From: mh Date: Mon, 2 Nov 2009 00:56:34 +0100 Subject: recursivly updating file path to new 0.25 style --- manifests/defines/concatenated_file.pp | 2 +- manifests/init.pp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/manifests/defines/concatenated_file.pp b/manifests/defines/concatenated_file.pp index 5a5144e..b6f8fb8 100644 --- a/manifests/defines/concatenated_file.pp +++ b/manifests/defines/concatenated_file.pp @@ -30,7 +30,7 @@ define concatenated_file ( } else { file { $dir_real: - source => "puppet:///common/empty", + source => "puppet://$server/modules/common/empty", checksum => mtime, ignore => '.ignore', recurse => true, purge => true, force => true, diff --git a/manifests/init.pp b/manifests/init.pp index f01ba24..b0a8ab2 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -7,7 +7,7 @@ file { # module-local data, e.g. for constructing config files "/var/lib/puppet/modules": ensure => directory, - source => "puppet://$server/common/modules/", + source => "puppet://$server/modules/common/modules/", ignore => '\.ignore', recurse => true, purge => true, force => true, mode => 0755, owner => root, group => 0; -- cgit v1.2.3 From acf0532464865e4b2cc84319d367bfba3599033a Mon Sep 17 00:00:00 2001 From: mh Date: Sun, 15 Nov 2009 18:10:51 +0100 Subject: fix missing urls to 0.25.x --- manifests/defines/modules_dir.pp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/manifests/defines/modules_dir.pp b/manifests/defines/modules_dir.pp index 797de2d..168c071 100644 --- a/manifests/defines/modules_dir.pp +++ b/manifests/defines/modules_dir.pp @@ -16,7 +16,7 @@ define modules_dir ( } else { file { "/var/lib/puppet/modules/${name}": - source => [ "puppet:///${name}/modules_dir", "puppet:///common/empty"], + source => [ "puppet://$server/${name}/modules_dir", "puppet://$server//modules/common/empty"], checksum => mtime, # ignore the placeholder ignore => '\.ignore', -- cgit v1.2.3 From 1a6eaf9c2e04693671c4631650278d90c7f2078f Mon Sep 17 00:00:00 2001 From: mh Date: Sun, 15 Nov 2009 18:15:04 +0100 Subject: fix missing urls to 0.25.x --- manifests/defines/modules_dir.pp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/manifests/defines/modules_dir.pp b/manifests/defines/modules_dir.pp index 168c071..4862e45 100644 --- a/manifests/defines/modules_dir.pp +++ b/manifests/defines/modules_dir.pp @@ -16,7 +16,7 @@ define modules_dir ( } else { file { "/var/lib/puppet/modules/${name}": - source => [ "puppet://$server/${name}/modules_dir", "puppet://$server//modules/common/empty"], + source => [ "puppet://$server/modules/${name}/modules_dir", "puppet://$server//modules/common/empty"], checksum => mtime, # ignore the placeholder ignore => '\.ignore', -- cgit v1.2.3 From 1b4f833b19f1036445dec143a0fd01b50ae16f29 Mon Sep 17 00:00:00 2001 From: mh Date: Mon, 16 Nov 2009 19:51:47 +0100 Subject: remove extra slash --- manifests/defines/modules_dir.pp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/manifests/defines/modules_dir.pp b/manifests/defines/modules_dir.pp index 4862e45..071fc56 100644 --- a/manifests/defines/modules_dir.pp +++ b/manifests/defines/modules_dir.pp @@ -16,7 +16,7 @@ define modules_dir ( } else { file { "/var/lib/puppet/modules/${name}": - source => [ "puppet://$server/modules/${name}/modules_dir", "puppet://$server//modules/common/empty"], + source => [ "puppet://$server/modules/${name}/modules_dir", "puppet://$server/modules/common/empty"], checksum => mtime, # ignore the placeholder ignore => '\.ignore', -- cgit v1.2.3 From 72dcd723629eba4b3ac4fd7d89303d4a110ad356 Mon Sep 17 00:00:00 2001 From: Andreas Date: Wed, 18 Nov 2009 16:53:57 +0100 Subject: generate a link --- manifests/defines/link.pp | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 manifests/defines/link.pp diff --git a/manifests/defines/link.pp b/manifests/defines/link.pp new file mode 100644 index 0000000..3325e4b --- /dev/null +++ b/manifests/defines/link.pp @@ -0,0 +1,20 @@ +# common/manifests/defines/link.pp -- create a link +# +# Copyleft (C) 2009 immerdaadmin +# See LICENSE for the full license granted to you. + +# Usage: +# link { "/usr/bin/convert": target => "/usr/local/bin/convert" } +# e.g. equivalent to bash# ln -s /usr/bin/convert /usr/local/bin/convert + +define link( + $target = 'absent' +) { + if ($target != 'absent') { + file { "$name": + ensure => link, + target => "${target}" + } + } +} + -- cgit v1.2.3 From 2a679f8fa07e050180c49a58012c9783971f5aa1 Mon Sep 17 00:00:00 2001 From: Andreas Date: Wed, 18 Nov 2009 19:22:01 +0100 Subject: remove link if absent --- manifests/defines/link.pp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/manifests/defines/link.pp b/manifests/defines/link.pp index 3325e4b..7bae08a 100644 --- a/manifests/defines/link.pp +++ b/manifests/defines/link.pp @@ -15,6 +15,12 @@ define link( ensure => link, target => "${target}" } + }else{ + file { "$name": + ensure => absent, + recurse => true, + force => true + } } } -- cgit v1.2.3 From d39201f8a224f1dd153818948d72f4c87d3fdf81 Mon Sep 17 00:00:00 2001 From: mh Date: Wed, 18 Nov 2009 23:34:39 +0100 Subject: make the define much easier --- manifests/defines/link.pp | 18 ++---------------- 1 file changed, 2 insertions(+), 16 deletions(-) diff --git a/manifests/defines/link.pp b/manifests/defines/link.pp index 7bae08a..e8e4a9f 100644 --- a/manifests/defines/link.pp +++ b/manifests/defines/link.pp @@ -7,20 +7,6 @@ # link { "/usr/bin/convert": target => "/usr/local/bin/convert" } # e.g. equivalent to bash# ln -s /usr/bin/convert /usr/local/bin/convert -define link( - $target = 'absent' -) { - if ($target != 'absent') { - file { "$name": - ensure => link, - target => "${target}" - } - }else{ - file { "$name": - ensure => absent, - recurse => true, - force => true - } - } +define link($target = absent) { + file{$name: ensure => $target; } } - -- cgit v1.2.3 From 75f88ffda0e3f2128ed4108d3ed0035c48f00c5b Mon Sep 17 00:00:00 2001 From: mh Date: Wed, 9 Dec 2009 23:57:37 +0100 Subject: add alias for compatibility --- manifests/defines/modules_dir.pp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/manifests/defines/modules_dir.pp b/manifests/defines/modules_dir.pp index 071fc56..36f9c18 100644 --- a/manifests/defines/modules_dir.pp +++ b/manifests/defines/modules_dir.pp @@ -25,3 +25,11 @@ define modules_dir ( } } } + +# alias for compatibility +define module_dir ( + $mode = 0644, $owner = root, $group = 0 + ) +{ + modules_dir{$name: mode => $mode, owner => $owner, group => $group } +} -- cgit v1.2.3 From b4ce2e8769aaee3e5c65f059a7056d956c6c3842 Mon Sep 17 00:00:00 2001 From: mh Date: Sat, 9 Jan 2010 14:23:03 +0100 Subject: make the removal of line safer --- manifests/defines/line.pp | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/manifests/defines/line.pp b/manifests/defines/line.pp index c055f5b..e5b7fd5 100644 --- a/manifests/defines/line.pp +++ b/manifests/defines/line.pp @@ -4,9 +4,9 @@ # Usage: # line { description: -# file => "filename", -# line => "content", -# ensure => {absent,*present*} +# file => "filename", +# line => "content", +# ensure => {absent,*present*} # } # # Example: @@ -24,19 +24,20 @@ # # define line($file, $line, $ensure = 'present') { - case $ensure { - default : { err ( "unknown ensure value '${ensure}'" ) } - present: { - exec { "echo '${line}' >> '${file}'": - unless => "grep -qFx '${line}' '${file}'" - } - } - absent: { - exec { "perl -ni -e 'print if \$_ ne \"${line}\n\";' '${file}'": - onlyif => "grep -qFx '${line}' '${file}'" - } - } - } + case $ensure { + default : { err ( "unknown ensure value '${ensure}'" ) } + present: { + exec { "echo '${line}' >> '${file}'": + unless => "grep -qFx '${line}' '${file}'" + } + } + absent: { + $subst_line = regsubst($line,'(/|\.)','\\\1','G') + exec { "/bin/sed -i '/${subst_line}/d' '${file}'": + onlyif => "/bin/grep -qFx '${line}' '${file}'" + } + } + } } -- cgit v1.2.3 From 9a70828ea0355a4cbbf5cbb91dfd2940a4cc1042 Mon Sep 17 00:00:00 2001 From: mh Date: Fri, 15 Jan 2010 09:46:31 +0100 Subject: set sed and grep relative --- manifests/defines/line.pp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/manifests/defines/line.pp b/manifests/defines/line.pp index e5b7fd5..7ca3191 100644 --- a/manifests/defines/line.pp +++ b/manifests/defines/line.pp @@ -33,8 +33,8 @@ define line($file, $line, $ensure = 'present') { } absent: { $subst_line = regsubst($line,'(/|\.)','\\\1','G') - exec { "/bin/sed -i '/${subst_line}/d' '${file}'": - onlyif => "/bin/grep -qFx '${line}' '${file}'" + exec { "sed -i '/${subst_line}/d' '${file}'": + onlyif => "grep -qFx '${line}' '${file}'" } } } -- cgit v1.2.3 From 9f336296301d595aa879f89331d9b720b3cf62a4 Mon Sep 17 00:00:00 2001 From: Jerome Charaoui Date: Mon, 15 Feb 2010 14:15:03 -0500 Subject: add $module_dir_path in modules_dir define for compatibility with David Schmitt's module --- manifests/defines/modules_dir.pp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/manifests/defines/modules_dir.pp b/manifests/defines/modules_dir.pp index 36f9c18..fe0d562 100644 --- a/manifests/defines/modules_dir.pp +++ b/manifests/defines/modules_dir.pp @@ -33,3 +33,7 @@ define module_dir ( { modules_dir{$name: mode => $mode, owner => $owner, group => $group } } + +# Use this variable to reference the base path. Thus you are safe from any +# changes. +$module_dir_path = '/var/lib/puppet/modules' -- cgit v1.2.3 From fcb2b08309e7ad18ee58283d754cb41b54fd79d1 Mon Sep 17 00:00:00 2001 From: Jerome Charaoui Date: Wed, 7 Apr 2010 14:25:08 -0400 Subject: concatenated_file: update define to latest from David Schmitt's common module --- manifests/defines/concatenated_file.pp | 51 +++++++++++++++++++++++++++------- 1 file 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 # 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 ( } } + -- cgit v1.2.3 From f3dde9f52a2d46f6ca949b87c3d6b15b90b4f6e4 Mon Sep 17 00:00:00 2001 From: Marcel Haerry Date: Wed, 5 May 2010 17:26:43 +0200 Subject: refactoring the last part of moduledirs --- manifests/defines/concatenated_file.pp | 5 ++--- manifests/defines/modules_dir.pp | 9 +++------ manifests/init.pp | 11 ----------- manifests/moduledir.pp | 15 +++++++++++++++ manifests/moduledir/common.pp | 3 +++ manifests/moduledir/common/cf.pp | 4 ++++ 6 files changed, 27 insertions(+), 20 deletions(-) create mode 100644 manifests/moduledir.pp create mode 100644 manifests/moduledir/common.pp create mode 100644 manifests/moduledir/common/cf.pp diff --git a/manifests/defines/concatenated_file.pp b/manifests/defines/concatenated_file.pp index d605219..8010c88 100644 --- a/manifests/defines/concatenated_file.pp +++ b/manifests/defines/concatenated_file.pp @@ -4,8 +4,6 @@ # Copyright (C) 2007 David Schmitt # See LICENSE for the full license granted to you. -module_dir { "common/cf": } - # TODO: # * create the directory in _part too @@ -40,11 +38,12 @@ define concatenated_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}" + $tmp_file = "${common::moduledir::module_dir_path}/${tmp_file_name}" if defined(File[$dir_real]) { debug("${dir_real} already defined") diff --git a/manifests/defines/modules_dir.pp b/manifests/defines/modules_dir.pp index fe0d562..c7cde5b 100644 --- a/manifests/defines/modules_dir.pp +++ b/manifests/defines/modules_dir.pp @@ -10,12 +10,13 @@ define modules_dir ( $mode = 0644, $owner = root, $group = 0 ) { - $dir = "/var/lib/puppet/modules/${name}" + include common::moduledir + $dir = "$common::moduledir::module_dir_path/${name}" if defined(File[$dir]) { debug("${dir} already defined") } else { file { - "/var/lib/puppet/modules/${name}": + $dir: source => [ "puppet://$server/modules/${name}/modules_dir", "puppet://$server/modules/common/empty"], checksum => mtime, # ignore the placeholder @@ -33,7 +34,3 @@ define module_dir ( { modules_dir{$name: mode => $mode, owner => $owner, group => $group } } - -# Use this variable to reference the base path. Thus you are safe from any -# changes. -$module_dir_path = '/var/lib/puppet/modules' diff --git a/manifests/init.pp b/manifests/init.pp index b0a8ab2..3770897 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -2,15 +2,4 @@ # Copyright (C) 2007 David Schmitt # See LICENSE for the full license granted to you. -file { - # Module programmers can use /var/lib/puppet/modules/$modulename to save - # module-local data, e.g. for constructing config files - "/var/lib/puppet/modules": - ensure => directory, - source => "puppet://$server/modules/common/modules/", - ignore => '\.ignore', - recurse => true, purge => true, force => true, - mode => 0755, owner => root, group => 0; -} - import "defines/*.pp" diff --git a/manifests/moduledir.pp b/manifests/moduledir.pp new file mode 100644 index 0000000..73f8775 --- /dev/null +++ b/manifests/moduledir.pp @@ -0,0 +1,15 @@ +class common::moduledir { + # Use this variable to reference the base path. Thus you are safe from any + # changes. + $module_dir_path = '/var/lib/puppet/modules' + + # Module programmers can use /var/lib/puppet/modules/$modulename to save + # module-local data, e.g. for constructing config files + file{$module_dir_path: + ensure => directory, + source => "puppet://$server/modules/common/modules/", + ignore => '\.ignore', + recurse => true, purge => true, force => true, + mode => 0755, owner => root, group => 0; + } +} diff --git a/manifests/moduledir/common.pp b/manifests/moduledir/common.pp new file mode 100644 index 0000000..c615f84 --- /dev/null +++ b/manifests/moduledir/common.pp @@ -0,0 +1,3 @@ +class common::moduledir::common{ + module_dir{'common': } +} diff --git a/manifests/moduledir/common/cf.pp b/manifests/moduledir/common/cf.pp new file mode 100644 index 0000000..b3c089b --- /dev/null +++ b/manifests/moduledir/common/cf.pp @@ -0,0 +1,4 @@ +class common::moduledir::common::cf { + include ::common::moduledir::common + module_dir{'common/cf': } +} -- cgit v1.2.3 From 109311524e3d63bb082b40db4caa25d650202511 Mon Sep 17 00:00:00 2001 From: Jerome Charaoui Date: Fri, 7 May 2010 16:55:38 -0400 Subject: document changes in module_dir usage --- manifests/defines/modules_dir.pp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/manifests/defines/modules_dir.pp b/manifests/defines/modules_dir.pp index c7cde5b..02398ea 100644 --- a/manifests/defines/modules_dir.pp +++ b/manifests/defines/modules_dir.pp @@ -5,12 +5,17 @@ # See LICENSE for the full license granted to you. # Usage: +# include common::moduledir # modules_dir { ["common", "common/dir1", "common/dir2" ]: } +# +# You may refer to a file in module_dir by using : +# file { "${common::moduledir::module_dir_path}/somedir/somefile": } + define modules_dir ( $mode = 0644, $owner = root, $group = 0 ) { - include common::moduledir + include common::moduledir $dir = "$common::moduledir::module_dir_path/${name}" if defined(File[$dir]) { debug("${dir} already defined") -- cgit v1.2.3 From 1379f6cba15c3e76ade83e5ec4b997879d4370e7 Mon Sep 17 00:00:00 2001 From: Jerome Charaoui Date: Fri, 7 May 2010 17:13:48 -0400 Subject: refactor modules_dir and modules_file to remove plural (deprecated in David Schmitt's version) and adjust module_file to new module_dir structure --- manifests/defines/module_dir.pp | 41 +++++++++++++++++++++++++++++++++++++++ manifests/defines/module_file.pp | 33 +++++++++++++++++++++++++++++++ manifests/defines/modules_dir.pp | 41 --------------------------------------- manifests/defines/modules_file.pp | 24 ----------------------- 4 files changed, 74 insertions(+), 65 deletions(-) create mode 100644 manifests/defines/module_dir.pp create mode 100644 manifests/defines/module_file.pp delete mode 100644 manifests/defines/modules_dir.pp delete mode 100644 manifests/defines/modules_file.pp diff --git a/manifests/defines/module_dir.pp b/manifests/defines/module_dir.pp new file mode 100644 index 0000000..73f5d75 --- /dev/null +++ b/manifests/defines/module_dir.pp @@ -0,0 +1,41 @@ +# common/manifests/defines/modules_dir.pp -- create a default directory +# for storing module specific information +# +# Copyright (C) 2007 David Schmitt +# See LICENSE for the full license granted to you. + +# Usage: +# include common::moduledir +# module_dir { ["common", "common/dir1", "common/dir2" ]: } +# +# You may refer to a file in module_dir by using : +# file { "${common::moduledir::module_dir_path}/somedir/somefile": } + +define module_dir ( + $mode = 0644, $owner = root, $group = 0 + ) +{ + include common::moduledir + $dir = "$common::moduledir::module_dir_path/${name}" + if defined(File[$dir]) { + debug("${dir} already defined") + } else { + file { + $dir: + source => [ "puppet://$server/modules/${name}/modules_dir", "puppet://$server/modules/common/empty"], + checksum => mtime, + # ignore the placeholder + ignore => '\.ignore', + recurse => true, purge => true, force => true, + mode => $mode, owner => $owner, group => $group; + } + } +} + +# alias for compatibility +define modules_dir ( + $mode = 0644, $owner = root, $group = 0 + ) +{ + module_dir { $name: mode => $mode, owner => $owner, group => $group } +} diff --git a/manifests/defines/module_file.pp b/manifests/defines/module_file.pp new file mode 100644 index 0000000..3c436ef --- /dev/null +++ b/manifests/defines/module_file.pp @@ -0,0 +1,33 @@ +# common/manifests/defines/modules_file.pp -- use a modules_dir to store module +# specific files +# +# Copyright (C) 2007 David Schmitt +# See LICENSE for the full license granted to you. + +# Usage: +# modules_file { "module/file": +# source => "puppet://${server}/...", +# mode => 644, # default +# owner => root, # default +# group => 0, # default +# } +define module_file ( + $source, + $mode = 0644, $owner = root, $group = 0 + ) +{ + include common::moduledir + file { + "${common::moduledir::module_dir_path}/${name}": + source => $source, + mode => $mode, owner => $owner, group => $group; + } +} + +# alias for compatibility +define modules_file ( + $source, $mode = 0644, $owner = root, $group = 0 + ) +{ + module_file { $name: source => $source, mode => $mode, owner => $owner, group => $group } +} diff --git a/manifests/defines/modules_dir.pp b/manifests/defines/modules_dir.pp deleted file mode 100644 index 02398ea..0000000 --- a/manifests/defines/modules_dir.pp +++ /dev/null @@ -1,41 +0,0 @@ -# common/manifests/defines/modules_dir.pp -- create a default directory -# for storing module specific information -# -# Copyright (C) 2007 David Schmitt -# See LICENSE for the full license granted to you. - -# Usage: -# include common::moduledir -# modules_dir { ["common", "common/dir1", "common/dir2" ]: } -# -# You may refer to a file in module_dir by using : -# file { "${common::moduledir::module_dir_path}/somedir/somefile": } - -define modules_dir ( - $mode = 0644, $owner = root, $group = 0 - ) -{ - include common::moduledir - $dir = "$common::moduledir::module_dir_path/${name}" - if defined(File[$dir]) { - debug("${dir} already defined") - } else { - file { - $dir: - source => [ "puppet://$server/modules/${name}/modules_dir", "puppet://$server/modules/common/empty"], - checksum => mtime, - # ignore the placeholder - ignore => '\.ignore', - recurse => true, purge => true, force => true, - mode => $mode, owner => $owner, group => $group; - } - } -} - -# alias for compatibility -define module_dir ( - $mode = 0644, $owner = root, $group = 0 - ) -{ - modules_dir{$name: mode => $mode, owner => $owner, group => $group } -} diff --git a/manifests/defines/modules_file.pp b/manifests/defines/modules_file.pp deleted file mode 100644 index 6a37242..0000000 --- a/manifests/defines/modules_file.pp +++ /dev/null @@ -1,24 +0,0 @@ -# common/manifests/defines/modules_file.pp -- use a modules_dir to store module -# specific files -# -# Copyright (C) 2007 David Schmitt -# See LICENSE for the full license granted to you. - -# Usage: -# modules_file { "module/file": -# source => "puppet://..", -# mode => 644, # default -# owner => root, # default -# group => root, # default -# } -define modules_file ( - $source, - $mode = 0644, $owner = root, $group = root - ) -{ - file { - "/var/lib/puppet/modules/${name}": - source => $source, - mode => $mode, owner => $owner, group => $group; - } -} -- cgit v1.2.3 From ca9b0fecd989df4877163f718ada342d7ca8a26b Mon Sep 17 00:00:00 2001 From: Jerome Charaoui Date: Fri, 7 May 2010 17:38:15 -0400 Subject: fix whitespace (remove tabs & trailing whitespace) --- manifests/defines/concatenated_file.pp | 147 ++++++++++++++++----------------- manifests/defines/config_file.pp | 40 ++++----- manifests/defines/module_dir.pp | 38 ++++----- manifests/defines/module_file.pp | 30 +++---- manifests/defines/replace.pp | 24 +++--- 5 files changed, 135 insertions(+), 144 deletions(-) diff --git a/manifests/defines/concatenated_file.pp b/manifests/defines/concatenated_file.pp index 8010c88..491e2c8 100644 --- a/manifests/defines/concatenated_file.pp +++ b/manifests/defines/concatenated_file.pp @@ -22,87 +22,78 @@ # # 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 - ) + # 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 = "${common::moduledir::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:///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: + 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 => 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]; + } - # 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 - } - #case $header { - #'': {} - #default: { Exec["concat_${name}"] { subscribe +> File[$header] } } - #} + # 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}' " + } + } - #case $footer { - #'': {} - #default: { Exec["concat_${name}"] { subscribe +> File[$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 + } } @@ -110,17 +101,17 @@ define concatenated_file ( # 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}"], + } } diff --git a/manifests/defines/config_file.pp b/manifests/defines/config_file.pp index cd6ccc3..e580715 100644 --- a/manifests/defines/config_file.pp +++ b/manifests/defines/config_file.pp @@ -4,10 +4,10 @@ # Usage: # config_file { filename: -# content => "....\n", +# content => "....\n", # } # -# Examples: +# Examples: # # To create the file /etc/vservers/${vs_name}/context with specific # content: @@ -28,26 +28,26 @@ # } define config_file ($content = '', $source = '', $ensure = 'present') { - file { $name: - ensure => $ensure, - # keep old versions on the server - backup => server, - # default permissions for config files - mode => 0644, owner => root, group => 0, - # really detect changes to this file - checksum => md5, - } + file { $name: + ensure => $ensure, + # keep old versions on the server + backup => server, + # default permissions for config files + mode => 0644, owner => root, group => 0, + # really detect changes to this file + checksum => md5, + } - case $source { - '': { } - default: { File[$name] { source => $source } } - } + case $source { + '': { } + default: { File[$name] { source => $source } } + } + + case $content { + '': { } + default: { File[$name] { content => $content } } + } - case $content { - '': { } - default: { File[$name] { content => $content } } - } - } diff --git a/manifests/defines/module_dir.pp b/manifests/defines/module_dir.pp index 73f5d75..7e2d10b 100644 --- a/manifests/defines/module_dir.pp +++ b/manifests/defines/module_dir.pp @@ -12,30 +12,30 @@ # file { "${common::moduledir::module_dir_path}/somedir/somefile": } define module_dir ( - $mode = 0644, $owner = root, $group = 0 - ) + $mode = 0644, $owner = root, $group = 0 + ) { - include common::moduledir - $dir = "$common::moduledir::module_dir_path/${name}" - if defined(File[$dir]) { - debug("${dir} already defined") - } else { - file { - $dir: - source => [ "puppet://$server/modules/${name}/modules_dir", "puppet://$server/modules/common/empty"], - checksum => mtime, - # ignore the placeholder - ignore => '\.ignore', - recurse => true, purge => true, force => true, - mode => $mode, owner => $owner, group => $group; - } - } + include common::moduledir + $dir = "$common::moduledir::module_dir_path/${name}" + if defined(File[$dir]) { + debug("${dir} already defined") + } else { + file { + $dir: + source => [ "puppet://$server/modules/${name}/modules_dir", "puppet://$server/modules/common/empty"], + checksum => mtime, + # ignore the placeholder + ignore => '\.ignore', + recurse => true, purge => true, force => true, + mode => $mode, owner => $owner, group => $group; + } + } } # alias for compatibility define modules_dir ( - $mode = 0644, $owner = root, $group = 0 - ) + $mode = 0644, $owner = root, $group = 0 + ) { module_dir { $name: mode => $mode, owner => $owner, group => $group } } diff --git a/manifests/defines/module_file.pp b/manifests/defines/module_file.pp index 3c436ef..6f84a32 100644 --- a/manifests/defines/module_file.pp +++ b/manifests/defines/module_file.pp @@ -6,28 +6,28 @@ # Usage: # modules_file { "module/file": -# source => "puppet://${server}/...", -# mode => 644, # default -# owner => root, # default -# group => 0, # default +# source => "puppet://${server}/...", +# mode => 644, # default +# owner => root, # default +# group => 0, # default # } define module_file ( - $source, - $mode = 0644, $owner = root, $group = 0 - ) + $source, + $mode = 0644, $owner = root, $group = 0 + ) { - include common::moduledir - file { - "${common::moduledir::module_dir_path}/${name}": - source => $source, - mode => $mode, owner => $owner, group => $group; - } + include common::moduledir + file { + "${common::moduledir::module_dir_path}/${name}": + source => $source, + mode => $mode, owner => $owner, group => $group; + } } # alias for compatibility define modules_file ( - $source, $mode = 0644, $owner = root, $group = 0 - ) + $source, $mode = 0644, $owner = root, $group = 0 + ) { module_file { $name: source => $source, mode => $mode, owner => $owner, group => $group } } diff --git a/manifests/defines/replace.pp b/manifests/defines/replace.pp index c13325e..7dabe59 100644 --- a/manifests/defines/replace.pp +++ b/manifests/defines/replace.pp @@ -4,7 +4,7 @@ # Usage: # -# replace { description: +# replace { description: # file => "filename", # pattern => "regexp", # replacement => "replacement" @@ -14,17 +14,17 @@ # with a new port, but only disturbing the file when needed: # # replace { set_munin_node_port: -# file => "/etc/munin/munin-node.conf", -# pattern => "^port (?!$port)[0-9]*", -# replacement => "port $port" -# } +# file => "/etc/munin/munin-node.conf", +# pattern => "^port (?!$port)[0-9]*", +# replacement => "port $port" +# } define replace($file, $pattern, $replacement) { - $pattern_no_slashes = slash_escape($pattern) - $replacement_no_slashes = slash_escape($replacement) - exec { "replace_${pattern}_${file}": - command => "/usr/bin/perl -pi -e 's/${pattern_no_slashes}/${replacement_no_slashes}/' '${file}'", - onlyif => "/usr/bin/perl -ne 'BEGIN { \$ret = 1; } \$ret = 0 if /${pattern_no_slashes}/ && ! /\\Q${replacement_no_slashes}\\E/; END { exit \$ret; }' '${file}'", - alias => "exec_$name", - } + $pattern_no_slashes = slash_escape($pattern) + $replacement_no_slashes = slash_escape($replacement) + exec { "replace_${pattern}_${file}": + command => "/usr/bin/perl -pi -e 's/${pattern_no_slashes}/${replacement_no_slashes}/' '${file}'", + onlyif => "/usr/bin/perl -ne 'BEGIN { \$ret = 1; } \$ret = 0 if /${pattern_no_slashes}/ && ! /\\Q${replacement_no_slashes}\\E/; END { exit \$ret; }' '${file}'", + alias => "exec_$name", + } } -- cgit v1.2.3 From d366f079d170004674481d25753aed362d4ef609 Mon Sep 17 00:00:00 2001 From: Jerome Charaoui Date: Fri, 7 May 2010 17:44:28 -0400 Subject: add esnure and alias paramaters to module_file --- manifests/defines/module_file.pp | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/manifests/defines/module_file.pp b/manifests/defines/module_file.pp index 6f84a32..e80c1ed 100644 --- a/manifests/defines/module_file.pp +++ b/manifests/defines/module_file.pp @@ -9,19 +9,26 @@ # source => "puppet://${server}/...", # mode => 644, # default # owner => root, # default -# group => 0, # default +# group => 0, # default # } define module_file ( - $source, - $mode = 0644, $owner = root, $group = 0 + $source, + $ensure = present, + $alias = 'absent', + $mode = 0644, $owner = root, $group = 0 ) { include common::moduledir file { "${common::moduledir::module_dir_path}/${name}": source => $source, + ensure => $ensure, mode => $mode, owner => $owner, group => $group; } + + if ($alias != 'absent') { + File["${common::moduledir::module_dir_path}/${name}"] { alias => $alias } + } } # alias for compatibility -- cgit v1.2.3 From bd774cd232b60a4c4048dbf604322ab78f1b7647 Mon Sep 17 00:00:00 2001 From: mh Date: Sun, 9 May 2010 23:10:05 +0200 Subject: quote var to be safer --- manifests/defines/module_dir.pp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/manifests/defines/module_dir.pp b/manifests/defines/module_dir.pp index 7e2d10b..e3b21e2 100644 --- a/manifests/defines/module_dir.pp +++ b/manifests/defines/module_dir.pp @@ -16,7 +16,7 @@ define module_dir ( ) { include common::moduledir - $dir = "$common::moduledir::module_dir_path/${name}" + $dir = "${common::moduledir::module_dir_path}/${name}" if defined(File[$dir]) { debug("${dir} already defined") } else { -- cgit v1.2.3 From e45a5794e7fc36d601ac047ef879f2b16f88a333 Mon Sep 17 00:00:00 2001 From: Jerome Charaoui Date: Mon, 10 May 2010 09:36:34 -0400 Subject: add ensure and alias parameters to modules_file compatiblity resource and use undef keywork for alias --- manifests/defines/module_file.pp | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/manifests/defines/module_file.pp b/manifests/defines/module_file.pp index e80c1ed..1b18c29 100644 --- a/manifests/defines/module_file.pp +++ b/manifests/defines/module_file.pp @@ -14,7 +14,7 @@ define module_file ( $source, $ensure = present, - $alias = 'absent', + $alias = undef, $mode = 0644, $owner = root, $group = 0 ) { @@ -23,18 +23,23 @@ define module_file ( "${common::moduledir::module_dir_path}/${name}": source => $source, ensure => $ensure, + alias => $alias, mode => $mode, owner => $owner, group => $group; } - - if ($alias != 'absent') { - File["${common::moduledir::module_dir_path}/${name}"] { alias => $alias } - } } # alias for compatibility define modules_file ( - $source, $mode = 0644, $owner = root, $group = 0 - ) + $source, + $ensure = present, + $alias = undef, + $mode = 0644, $owner = root, $group = 0 + ) { - module_file { $name: source => $source, mode => $mode, owner => $owner, group => $group } + module_file { $name: + source => $source, + ensure => $ensure, + alias => $alias, + mode => $mode, owner => $owner, group => $group + } } -- cgit v1.2.3 From 506be3f70ff03757eb3425f04a61dff41fc6cdc0 Mon Sep 17 00:00:00 2001 From: mh Date: Tue, 20 Jul 2010 00:35:16 +0200 Subject: remove escaping --- manifests/moduledir.pp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/manifests/moduledir.pp b/manifests/moduledir.pp index 73f8775..607d6f5 100644 --- a/manifests/moduledir.pp +++ b/manifests/moduledir.pp @@ -8,7 +8,7 @@ class common::moduledir { file{$module_dir_path: ensure => directory, source => "puppet://$server/modules/common/modules/", - ignore => '\.ignore', + ignore => '.ignore', recurse => true, purge => true, force => true, mode => 0755, owner => root, group => 0; } -- cgit v1.2.3 From 533ec99736496611be4d9ed3bb6692b6590fecb5 Mon Sep 17 00:00:00 2001 From: mh Date: Tue, 20 Jul 2010 00:35:46 +0200 Subject: remove escaping --- manifests/defines/module_dir.pp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/manifests/defines/module_dir.pp b/manifests/defines/module_dir.pp index e3b21e2..39fef8c 100644 --- a/manifests/defines/module_dir.pp +++ b/manifests/defines/module_dir.pp @@ -25,7 +25,7 @@ define module_dir ( source => [ "puppet://$server/modules/${name}/modules_dir", "puppet://$server/modules/common/empty"], checksum => mtime, # ignore the placeholder - ignore => '\.ignore', + ignore => '.ignore', recurse => true, purge => true, force => true, mode => $mode, owner => $owner, group => $group; } -- cgit v1.2.3 From 619f43a1bcc1fd702228aefc14d0db71b437429b Mon Sep 17 00:00:00 2001 From: mh Date: Wed, 21 Jul 2010 07:51:28 +0200 Subject: Revert "remove escaping" This reverts commit 40e3048d060f10105ae9dff524d5fa7901523a3e. --- manifests/defines/module_dir.pp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/manifests/defines/module_dir.pp b/manifests/defines/module_dir.pp index 39fef8c..e3b21e2 100644 --- a/manifests/defines/module_dir.pp +++ b/manifests/defines/module_dir.pp @@ -25,7 +25,7 @@ define module_dir ( source => [ "puppet://$server/modules/${name}/modules_dir", "puppet://$server/modules/common/empty"], checksum => mtime, # ignore the placeholder - ignore => '.ignore', + ignore => '\.ignore', recurse => true, purge => true, force => true, mode => $mode, owner => $owner, group => $group; } -- cgit v1.2.3 From 51d64164a9862086b2071035459ade582dcc6aea Mon Sep 17 00:00:00 2001 From: mh Date: Wed, 21 Jul 2010 07:51:44 +0200 Subject: Revert "remove escaping" This reverts commit 7cc9d114afc9d5c807a7ee30bff7aaba865aded3. --- manifests/moduledir.pp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/manifests/moduledir.pp b/manifests/moduledir.pp index 607d6f5..73f8775 100644 --- a/manifests/moduledir.pp +++ b/manifests/moduledir.pp @@ -8,7 +8,7 @@ class common::moduledir { file{$module_dir_path: ensure => directory, source => "puppet://$server/modules/common/modules/", - ignore => '.ignore', + ignore => '\.ignore', recurse => true, purge => true, force => true, mode => 0755, owner => root, group => 0; } -- cgit v1.2.3 From 8904d702218333394e1d8c8ba788d9d2bce85645 Mon Sep 17 00:00:00 2001 From: mh Date: Wed, 21 Jul 2010 07:54:31 +0200 Subject: cleanup escaping stuff --- manifests/defines/concatenated_file.pp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/manifests/defines/concatenated_file.pp b/manifests/defines/concatenated_file.pp index 491e2c8..2985442 100644 --- a/manifests/defines/concatenated_file.pp +++ b/manifests/defines/concatenated_file.pp @@ -52,7 +52,7 @@ define concatenated_file ( $dir_real: source => "puppet:///modules/common/empty", checksum => mtime, - ignore => '.ignore', + ignore => '\.ignore', recurse => true, purge => true, force => true, mode => $mode, owner => $owner, group => $group, notify => Exec["concat_${name}"]; -- cgit v1.2.3 From e5de903a2200cad66e7145c90f1c5ed6c2c88a4e Mon Sep 17 00:00:00 2001 From: mh Date: Mon, 2 Aug 2010 01:53:41 +0200 Subject: escaping --- manifests/defines/concatenated_file.pp | 2 +- manifests/defines/module_dir.pp | 2 +- manifests/moduledir.pp | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/manifests/defines/concatenated_file.pp b/manifests/defines/concatenated_file.pp index 2985442..491e2c8 100644 --- a/manifests/defines/concatenated_file.pp +++ b/manifests/defines/concatenated_file.pp @@ -52,7 +52,7 @@ define concatenated_file ( $dir_real: source => "puppet:///modules/common/empty", checksum => mtime, - ignore => '\.ignore', + ignore => '.ignore', recurse => true, purge => true, force => true, mode => $mode, owner => $owner, group => $group, notify => Exec["concat_${name}"]; diff --git a/manifests/defines/module_dir.pp b/manifests/defines/module_dir.pp index e3b21e2..39fef8c 100644 --- a/manifests/defines/module_dir.pp +++ b/manifests/defines/module_dir.pp @@ -25,7 +25,7 @@ define module_dir ( source => [ "puppet://$server/modules/${name}/modules_dir", "puppet://$server/modules/common/empty"], checksum => mtime, # ignore the placeholder - ignore => '\.ignore', + ignore => '.ignore', recurse => true, purge => true, force => true, mode => $mode, owner => $owner, group => $group; } diff --git a/manifests/moduledir.pp b/manifests/moduledir.pp index 73f8775..607d6f5 100644 --- a/manifests/moduledir.pp +++ b/manifests/moduledir.pp @@ -8,7 +8,7 @@ class common::moduledir { file{$module_dir_path: ensure => directory, source => "puppet://$server/modules/common/modules/", - ignore => '\.ignore', + ignore => '.ignore', recurse => true, purge => true, force => true, mode => 0755, owner => root, group => 0; } -- cgit v1.2.3 From 836316955a468d419416b9c28ebcc76dc577f199 Mon Sep 17 00:00:00 2001 From: mh Date: Sat, 7 Aug 2010 02:12:13 +0200 Subject: remove unnecessary fileserver variable (#2460) --- manifests/defines/module_dir.pp | 2 +- manifests/moduledir.pp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/manifests/defines/module_dir.pp b/manifests/defines/module_dir.pp index 39fef8c..613cc49 100644 --- a/manifests/defines/module_dir.pp +++ b/manifests/defines/module_dir.pp @@ -22,7 +22,7 @@ define module_dir ( } else { file { $dir: - source => [ "puppet://$server/modules/${name}/modules_dir", "puppet://$server/modules/common/empty"], + source => [ "puppet:///modules/${name}/modules_dir", "puppet:///modules/common/empty"], checksum => mtime, # ignore the placeholder ignore => '.ignore', diff --git a/manifests/moduledir.pp b/manifests/moduledir.pp index 607d6f5..df83e60 100644 --- a/manifests/moduledir.pp +++ b/manifests/moduledir.pp @@ -7,7 +7,7 @@ class common::moduledir { # module-local data, e.g. for constructing config files file{$module_dir_path: ensure => directory, - source => "puppet://$server/modules/common/modules/", + source => "puppet:///modules/common/modules/", ignore => '.ignore', recurse => true, purge => true, force => true, mode => 0755, owner => root, group => 0; -- cgit v1.2.3 From 51e06fd0d2fa1c8999f328051e5e717bc18e77e7 Mon Sep 17 00:00:00 2001 From: mh Date: Wed, 11 Aug 2010 15:56:40 +0200 Subject: remove unnecessary fileserver variable (#2460) round II --- manifests/defines/module_file.pp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/manifests/defines/module_file.pp b/manifests/defines/module_file.pp index 1b18c29..43b3c48 100644 --- a/manifests/defines/module_file.pp +++ b/manifests/defines/module_file.pp @@ -6,7 +6,7 @@ # Usage: # modules_file { "module/file": -# source => "puppet://${server}/...", +# source => "puppet:///...", # mode => 644, # default # owner => root, # default # group => 0, # default -- cgit v1.2.3 From a0818f9b36f2237f5b376207f0c5ddf92425f409 Mon Sep 17 00:00:00 2001 From: Jerome Charaoui Date: Tue, 21 Sep 2010 16:28:57 -0400 Subject: Use default 'puppet' filebucket instead of arbitrary 'server' for config_file backup --- manifests/defines/config_file.pp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/manifests/defines/config_file.pp b/manifests/defines/config_file.pp index e580715..2272558 100644 --- a/manifests/defines/config_file.pp +++ b/manifests/defines/config_file.pp @@ -31,7 +31,7 @@ define config_file ($content = '', $source = '', $ensure = 'present') { file { $name: ensure => $ensure, # keep old versions on the server - backup => server, + backup => puppet, # default permissions for config files mode => 0644, owner => root, group => 0, # really detect changes to this file -- cgit v1.2.3 From 63322aa30578c69772d2f1e266a8534b12874a0f Mon Sep 17 00:00:00 2001 From: Jerome Charaoui Date: Fri, 24 Sep 2010 14:41:07 -0400 Subject: Add multi_source_template function --- .../parser/functions/multi_source_template.rb | 29 ++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 lib/puppet/parser/functions/multi_source_template.rb diff --git a/lib/puppet/parser/functions/multi_source_template.rb b/lib/puppet/parser/functions/multi_source_template.rb new file mode 100644 index 0000000..e075320 --- /dev/null +++ b/lib/puppet/parser/functions/multi_source_template.rb @@ -0,0 +1,29 @@ +module Puppet::Parser::Functions + require 'erb' + + newfunction(:multi_source_template, :type => :rvalue) do |args| + contents = nil + environment = compiler.environment + sources = args + + sources.each do |file| + Puppet.debug("Looking for #{file} in #{environment}") + if filename = Puppet::Parser::Files.find_template(file, environment.to_s) + wrapper = Puppet::Parser::TemplateWrapper.new(self) + wrapper.file = file + + begin + contents = wrapper.result + rescue => detail + raise Puppet::ParseError, "Failed to parse template %s: %s" % [file, detail] + end + + break + end + end + + raise Puppet::ParseError, "multi_source_template: No match found for files: #{sources.join(', ')}" if contents == nil + + contents + end +end -- cgit v1.2.3 From 90a172d01f13924954384229655b5098db0cbb73 Mon Sep 17 00:00:00 2001 From: mh Date: Thu, 21 Oct 2010 00:04:25 +0200 Subject: remove some legacy functions that are now in upstream --- lib/puppet/parser/functions/sha1.rb | 9 --------- lib/puppet/parser/functions/split.rb | 17 ----------------- 2 files changed, 26 deletions(-) delete mode 100644 lib/puppet/parser/functions/sha1.rb delete mode 100644 lib/puppet/parser/functions/split.rb diff --git a/lib/puppet/parser/functions/sha1.rb b/lib/puppet/parser/functions/sha1.rb deleted file mode 100644 index b5aa813..0000000 --- a/lib/puppet/parser/functions/sha1.rb +++ /dev/null @@ -1,9 +0,0 @@ -# return the sha1 hash -require 'digest/sha1' - -module Puppet::Parser::Functions - newfunction(:sha1, :type => :rvalue) do |args| - Digest::SHA1.hexdigest(args[0]) - end -end - diff --git a/lib/puppet/parser/functions/split.rb b/lib/puppet/parser/functions/split.rb deleted file mode 100644 index 5237c92..0000000 --- a/lib/puppet/parser/functions/split.rb +++ /dev/null @@ -1,17 +0,0 @@ -# split($string, $delimiter) : $string -# split($string[], $delimiter) : $string[][] -# -# Split the first argument(s) on every $delimiter. $delimiter is interpreted as -# Ruby regular expression. -# -# For long-term portability it is recommended to refrain from using Ruby's -# extended RE features. -module Puppet::Parser::Functions - newfunction(:split, :type => :rvalue) do |args| - if args[0].is_a?(Array) - args.collect do |a| a.split(/#{args[1]}/) end - else - args[0].split(/#{args[1]}/) - end - end -end -- cgit v1.2.3 From 2dd17923bf6787029aee00d0b0e1e8dfbb0a5e7f Mon Sep 17 00:00:00 2001 From: mh Date: Thu, 21 Oct 2010 00:10:28 +0200 Subject: add a join function --- lib/puppet/parser/functions/join.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 lib/puppet/parser/functions/join.rb diff --git a/lib/puppet/parser/functions/join.rb b/lib/puppet/parser/functions/join.rb new file mode 100644 index 0000000..95b664c --- /dev/null +++ b/lib/puppet/parser/functions/join.rb @@ -0,0 +1,10 @@ +Puppet::Parser::Functions::newfunction( + :join, + :type => :rvalue, + :doc => "Joins the values of the array in arg1 with the string in arg2 + + Example: join(['a','b'],',') -> 'a,b'" +) do |args| + raise Puppet::ParseError, 'join() needs two arguments' if args.length != 2 + args[0].to_a.join(args[1]) +end -- cgit v1.2.3 From 82eed89bccfe1af07caf925ce91e43b878bfda41 Mon Sep 17 00:00:00 2001 From: mh Date: Thu, 21 Oct 2010 00:40:23 +0200 Subject: add a function to do some array work --- lib/puppet/parser/functions/uniq_flatten.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 lib/puppet/parser/functions/uniq_flatten.rb diff --git a/lib/puppet/parser/functions/uniq_flatten.rb b/lib/puppet/parser/functions/uniq_flatten.rb new file mode 100644 index 0000000..a4cae40 --- /dev/null +++ b/lib/puppet/parser/functions/uniq_flatten.rb @@ -0,0 +1,10 @@ +Puppet::Parser::Functions::newfunction( + :uniq_flatten, + :type => :rvalue, + :doc => "Flattens an array and make it uniq + + Example: uniq_flatten([['a','b'],'a']) -> ['a','b']" +) do |args| + raise Puppet::ParseError, 'uniq_flatten() needs one arguments' if args.length != 1 + args[0].to_a.flatten.uniq +end -- cgit v1.2.3 From 218c68752e3096b79cc9dc2a8749b9776715ade8 Mon Sep 17 00:00:00 2001 From: mh Date: Thu, 21 Oct 2010 01:05:22 +0200 Subject: go on uniq strings Looks like puppet has some internal representation which is not comparable. --- lib/puppet/parser/functions/uniq_flatten.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/puppet/parser/functions/uniq_flatten.rb b/lib/puppet/parser/functions/uniq_flatten.rb index a4cae40..4841c4d 100644 --- a/lib/puppet/parser/functions/uniq_flatten.rb +++ b/lib/puppet/parser/functions/uniq_flatten.rb @@ -6,5 +6,5 @@ Puppet::Parser::Functions::newfunction( Example: uniq_flatten([['a','b'],'a']) -> ['a','b']" ) do |args| raise Puppet::ParseError, 'uniq_flatten() needs one arguments' if args.length != 1 - args[0].to_a.flatten.uniq + args[0].to_a.flatten.collect(&:to_s).uniq end -- cgit v1.2.3 From f8d9e9fd83f20c3846d26faf5cff3546bcea3b79 Mon Sep 17 00:00:00 2001 From: mh Date: Thu, 21 Oct 2010 01:53:48 +0200 Subject: enable possibility to set a concatenated file to absent --- manifests/defines/concatenated_file.pp | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/manifests/defines/concatenated_file.pp b/manifests/defines/concatenated_file.pp index 491e2c8..5f1c275 100644 --- a/manifests/defines/concatenated_file.pp +++ b/manifests/defines/concatenated_file.pp @@ -28,6 +28,7 @@ # dir => "/etc/some.conf.d", # } define concatenated_file ( + $ensure = 'present', # where the snippets are located $dir = '', # a file with content to prepend @@ -50,6 +51,10 @@ define concatenated_file ( } else { file { $dir_real: + ensure => $ensure ? { + 'present' => directory, + default => $ensure + }, source => "puppet:///modules/common/empty", checksum => mtime, ignore => '.ignore', @@ -61,40 +66,41 @@ define concatenated_file ( file { $tmp_file: - ensure => present, checksum => md5, + 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 => present, checksum => md5, + ensure => $ensure, 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 - $additional_cmd = $header ? { + if $ensure == 'present' { + # if there is a header or footer file, add it + $additional_cmd = $header ? { '' => $footer ? { - '' => '', - default => "| cat - '${footer}' " + '' => '', + default => "| cat - '${footer}' " }, default => $footer ? { - '' => "| cat '${header}' - ", - default => "| cat '${header}' - '${footer}' " + '' => "| cat '${header}' - ", + default => "| cat '${header}' - '${footer}' " } - } + } - # use >| to force clobbering the target file - exec { "concat_${name}": + # 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 + } } - } -- cgit v1.2.3 From ba430647940c1cfbf3e220f032804da325da94a7 Mon Sep 17 00:00:00 2001 From: mh Date: Thu, 28 Oct 2010 00:19:44 +0200 Subject: add a new function & tests for that function --- lib/puppet/parser/functions/array_del.rb | 11 +++++++++ spec/spec.opts | 6 +++++ spec/spec_helper.rb | 16 +++++++++++++ spec/unit/parser/functions/array_del.rb | 39 ++++++++++++++++++++++++++++++++ 4 files changed, 72 insertions(+) create mode 100644 lib/puppet/parser/functions/array_del.rb create mode 100644 spec/spec.opts create mode 100644 spec/spec_helper.rb create mode 100644 spec/unit/parser/functions/array_del.rb diff --git a/lib/puppet/parser/functions/array_del.rb b/lib/puppet/parser/functions/array_del.rb new file mode 100644 index 0000000..e604916 --- /dev/null +++ b/lib/puppet/parser/functions/array_del.rb @@ -0,0 +1,11 @@ +Puppet::Parser::Functions::newfunction( + :array_del, + :type => :rvalue, + :doc => "Deletes items from an array + + Example: array_del(['a','b'],'b') -> ['a']" +) do |args| + raise Puppet::ParseError, 'array_del() needs two arguments' if args.length != 2 + (res=args[0].dup).to_a.delete(args[1]) + res +end diff --git a/spec/spec.opts b/spec/spec.opts new file mode 100644 index 0000000..91cd642 --- /dev/null +++ b/spec/spec.opts @@ -0,0 +1,6 @@ +--format +s +--colour +--loadby +mtime +--backtrace diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb new file mode 100644 index 0000000..6ba62e1 --- /dev/null +++ b/spec/spec_helper.rb @@ -0,0 +1,16 @@ +require 'pathname' +dir = Pathname.new(__FILE__).parent +$LOAD_PATH.unshift(dir, dir + 'lib', dir + '../lib') +require 'puppet' +gem 'rspec', '>= 1.2.9' +require 'spec/autorun' + +Dir[File.join(File.dirname(__FILE__), 'support', '*.rb')].each do |support_file| + require support_file +end + +# We need this because the RAL uses 'should' as a method. This +# allows us the same behaviour but with a different method name. +class Object + alias :must :should +end diff --git a/spec/unit/parser/functions/array_del.rb b/spec/unit/parser/functions/array_del.rb new file mode 100644 index 0000000..b375862 --- /dev/null +++ b/spec/unit/parser/functions/array_del.rb @@ -0,0 +1,39 @@ +#! /usr/bin/env ruby + +require File.dirname(__FILE__) + '/../../../spec_helper' + +describe "the array_del function" do + + before :each do + @scope = Puppet::Parser::Scope.new + end + + it "should exist" do + Puppet::Parser::Functions.function("array_del").should == "function_array_del" + end + + it "should raise a ParseError if there is less than 2 arguments" do + lambda { @scope.function_array_del(["foo"]) }.should( raise_error(Puppet::ParseError)) + end + + it "should raise a ParseError if there is more than 2 arguments" do + lambda { @scope.function_array_del(["foo", "bar", "gazonk"]) }.should( raise_error(Puppet::ParseError)) + end + + it "should remove an item if it's present" do + result = @scope.function_array_del(['a','b'],'b') + result.should(eql(['a'])) + end + + it "should do nothing if an item is not present" do + result = @scope.function_array_del(['a','b'],'c') + result.should(eql(['a','b'])) + end + + it "should leave the argument untouched" do + a = ['a','b'] + result = @scope.function_array_del(a,'b') + a.should(eql(['a','b'])) + end + +end -- cgit v1.2.3