From: Micah Anderson Date: Thu, 2 Sep 2010 23:04:29 +0000 (-0400) Subject: Merge remote branch 'immerda/master' X-Git-Url: https://gitweb.fluxo.info/?a=commitdiff_plain;h=63a16ad8c07e880e68cb7c0a895f7e26ca1434f8;p=puppet-common.git Merge remote branch 'immerda/master' Conflicts: lib/puppet/parser/functions/gsub.rb lib/puppet/parser/functions/prefix_with.rb lib/puppet/parser/functions/sha1.rb lib/puppet/parser/functions/slash_escape.rb lib/puppet/parser/functions/substitute.rb manifests/classes/lsb_release.pp manifests/defines/concatenated_file.pp manifests/defines/config_file.pp manifests/defines/line.pp manifests/defines/module_dir.pp manifests/defines/module_file.pp manifests/defines/replace.pp manifests/init.pp --- 63a16ad8c07e880e68cb7c0a895f7e26ca1434f8 diff --cc manifests/defines/config_file.pp index 781e9ec,e580715..d624c10 --- a/manifests/defines/config_file.pp +++ b/manifests/defines/config_file.pp @@@ -2,14 -2,12 +2,14 @@@ # Copyright (C) 2007 David Schmitt # See LICENSE for the full license granted to you. +# A simple wrapper to give all configuration files common defaults. - # ++# # Usage: - # config_file { filename: - # content => "....\n", - # } + # config_file { filename: + # content => "....\n", + # } # - # Examples: + # Examples: # # To create the file /etc/vservers/${vs_name}/context with specific # content: diff --cc manifests/defines/line.pp index bc2ece4,7ca3191..ccfa357 --- a/manifests/defines/line.pp +++ b/manifests/defines/line.pp @@@ -2,56 -2,42 +2,53 @@@ # Copyright (C) 2007 David Schmitt # See LICENSE for the full license granted to you. -# Usage: -# line { description: -# file => "filename", -# line => "content", -# ensure => {absent,*present*} -# } +# Ensures that a specific line is present or absent in a file. This can +# be very brittle, since even small changes can throw this off. # -# Example: -# The following ensures that the line "allow ^$munin_host$" exists -# in /etc/munin/munin-node.conf, and if there are any changes notify the service for -# a restart +# If the line is not present yet, it will be appended to the file. +# +# The name of the define is not used. Just keep it (globally) unique and +# descriptive. # -# line { allow_munin_host: -# file => "/etc/munin/munin-node.conf", -# line => "allow ^$munin_host$", -# ensure => present, -# notify => Service[munin-node], -# require => Package[munin-node], +# Use this only for very trivial stuff. Usually replacing the whole file +# is a more stable solution with less maintenance headaches afterwards. +# +# Usage: +# line { +# description: +# file => "filename", +# line => "content", +# ensure => {absent,*present*} # } # +# Example: +# The following ensures that the line "allow ^$munin_host$" exists in +# /etc/munin/munin-node.conf, and if there are any changes notify the +# service for a restart # +# line { +# allow_munin_host: +# file => "/etc/munin/munin-node.conf", +# line => "allow ^$munin_host$", +# ensure => present, +# notify => Service[munin-node], +# require => Package[munin-node]; +# } - 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}'" - } - } - } + 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: { + $subst_line = regsubst($line,'(/|\.)','\\\1','G') + exec { "sed -i '/${subst_line}/d' '${file}'": + onlyif => "grep -qFx '${line}' '${file}'" + } + } + } } diff --cc manifests/defines/module_dir.pp index def5c94,613cc49..227fe71 --- a/manifests/defines/module_dir.pp +++ b/manifests/defines/module_dir.pp @@@ -4,39 -4,38 +4,47 @@@ # Copyright (C) 2007 David Schmitt # See LICENSE for the full license granted to you. +# A module_dir is a storage place for all the stuff a module might want to +# store. According to the FHS, this should go to /var/lib. Since this is a part +# of puppet, the full path is /var/lib/puppet/modules/${name}. Every module +# should # prefix its module_dirs with its name. +# +# By default, the module_dir is loaded from "puppet:///${name}/module_dir". If +# that doesn't exist an empty directory is taken as source. The directory is +# purged so that modules do not have to worry about removing cruft. +# # Usage: - # module_dir { ["common", "common/dir1", "common/dir2" ]: } + # 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 - ) + $mode = 0644, $owner = root, $group = 0 + ) { - $dir = "${module_dir_path}/${name}" - if defined(File[$dir]) { - debug("${dir} already defined") - } else { - file { - $dir: - source => [ "puppet://$server/modules/${name}/module_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:///modules/${name}/modules_dir", "puppet:///modules/common/empty"], + checksum => mtime, + # ignore the placeholder + ignore => '.ignore', + recurse => true, purge => true, force => true, + 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' + # alias for compatibility + define modules_dir ( + $mode = 0644, $owner = root, $group = 0 + ) + { + module_dir { $name: mode => $mode, owner => $owner, group => $group } + } diff --cc manifests/defines/module_file.pp index 9074589,43b3c48..70e5cbf --- a/manifests/defines/module_file.pp +++ b/manifests/defines/module_file.pp @@@ -4,21 -4,42 +4,44 @@@ # Copyright (C) 2007 David Schmitt # See LICENSE for the full license granted to you. +# Put a file into module-local storage. +# # Usage: - # module_file { - # "module/file": - # source => "puppet://..", + # modules_file { "module/file": + # source => "puppet:///...", + # mode => 644, # default + # owner => root, # default + # group => 0, # default # } define module_file ( - $source, - $mode = 0644, $owner = root, $group = 0 - ) + $source, + $ensure = present, + $alias = undef, + $mode = 0644, $owner = root, $group = 0 + ) { - file { - "${module_dir_path}/${name}": - source => $source, - mode => $mode, owner => $owner, group => $group; - } + include common::moduledir + file { + "${common::moduledir::module_dir_path}/${name}": + source => $source, + ensure => $ensure, + alias => $alias, + mode => $mode, owner => $owner, group => $group; + } + } + + # alias for compatibility + define modules_file ( + $source, + $ensure = present, + $alias = undef, + $mode = 0644, $owner = root, $group = 0 + ) + { + module_file { $name: + source => $source, + ensure => $ensure, + alias => $alias, + mode => $mode, owner => $owner, group => $group + } } diff --cc manifests/defines/replace.pp index c9a98bd,7dabe59..f7da3b4 --- a/manifests/defines/replace.pp +++ b/manifests/defines/replace.pp @@@ -2,19 -2,9 +2,19 @@@ # Copyright (C) 2007 David Schmitt # See LICENSE for the full license granted to you. +# A hack to replace all ocurrances of a regular expression in a file with a +# specified string. Sometimes it can be less effort to replace only a single +# value in a huge config file instead of creating a template out of it. Still, +# creating a template is often better than this hack. +# +# This define uses perl regular expressions. +# +# Use this only for very trivial stuff. Usually replacing the whole file is a +# more stable solution with less maintenance headaches afterwards. +# # Usage: # - # replace { description: + # replace { description: # file => "filename", # pattern => "regexp", # replacement => "replacement" diff --cc manifests/init.pp index f767030,3770897..3a9faf5 --- a/manifests/init.pp +++ b/manifests/init.pp @@@ -3,23 -3,3 +3,4 @@@ # See LICENSE for the full license granted to you. import "defines/*.pp" - import "classes/*.pp" - - module_dir { [ 'common' ]: } - - file { - # Module programmers can use /var/lib/puppet/modules/$modulename to save - # module-local data, e.g. for constructing config files. See module_dir - # for details - "/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; - } - - # common packages - class pkg::openssl { package { openssl: ensure => installed } } - class pkg::rsync { package { rsync: ensure => installed } } +