Merge pull request #18 from dalen/master
A patch to make puppet-concat better comply with community style guidelines.
This commit is contained in:
commit
e9c97b8820
3 changed files with 135 additions and 139 deletions
|
@ -13,39 +13,37 @@
|
||||||
# - group Owner of the file
|
# - group Owner of the file
|
||||||
# - backup Controls the filebucketing behavior of the final file and
|
# - backup Controls the filebucketing behavior of the final file and
|
||||||
# see File type reference for its use. Defaults to 'puppet'
|
# see File type reference for its use. Defaults to 'puppet'
|
||||||
define concat::fragment($target, $content='', $source='', $order=10, $ensure = "present", $mode = 0644, $owner = $::id, $group = $concat::setup::root_group, $backup = "puppet") {
|
define concat::fragment($target, $content='', $source='', $order=10, $ensure = 'present', $mode = '0644', $owner = $::id, $group = $concat::setup::root_group, $backup = 'puppet') {
|
||||||
$safe_name = regsubst($name, '/', '_', 'G')
|
$safe_name = regsubst($name, '/', '_', 'G')
|
||||||
$safe_target_name = regsubst($target, '/', '_', 'G')
|
$safe_target_name = regsubst($target, '/', '_', 'G')
|
||||||
$concatdir = $concat::setup::concatdir
|
$concatdir = $concat::setup::concatdir
|
||||||
$fragdir = "${concatdir}/${safe_target_name}"
|
$fragdir = "${concatdir}/${safe_target_name}"
|
||||||
|
|
||||||
# if content is passed, use that, else if source is passed use that
|
# if content is passed, use that, else if source is passed use that
|
||||||
# if neither passed, but $ensure is in symlink form, make a symlink
|
# if neither passed, but $ensure is in symlink form, make a symlink
|
||||||
case $content {
|
case $content {
|
||||||
"": {
|
'': {
|
||||||
case $source {
|
case $source {
|
||||||
"": {
|
'': {
|
||||||
case $ensure {
|
case $ensure {
|
||||||
"", "absent", "present", "file", "directory": {
|
'', 'absent', 'present', 'file', 'directory': {
|
||||||
crit("No content, source or symlink specified")
|
crit('No content, source or symlink specified')
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
default: { File{ source => $source } }
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
default: { File{ content => $content } }
|
}
|
||||||
|
}
|
||||||
|
default: { File{ source => $source } }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
default: { File{ content => $content } }
|
||||||
|
}
|
||||||
|
|
||||||
file{"${fragdir}/fragments/${order}_${safe_name}":
|
file{"${fragdir}/fragments/${order}_${safe_name}":
|
||||||
mode => $mode,
|
ensure => $ensure,
|
||||||
owner => $owner,
|
mode => $mode,
|
||||||
group => $group,
|
owner => $owner,
|
||||||
ensure => $ensure,
|
group => $group,
|
||||||
backup => $backup,
|
backup => $backup,
|
||||||
alias => "concat_fragment_${name}",
|
alias => "concat_fragment_${name}",
|
||||||
notify => Exec["concat_${target}"]
|
notify => Exec["concat_${target}"]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
# vi:tabstop=4:expandtab:ai
|
|
||||||
|
|
|
@ -87,88 +87,88 @@
|
||||||
# ALIASES:
|
# ALIASES:
|
||||||
# - The exec can notified using Exec["concat_/path/to/file"] or Exec["concat_/path/to/directory"]
|
# - The exec can notified using Exec["concat_/path/to/file"] or Exec["concat_/path/to/directory"]
|
||||||
# - The final file can be referened as File["/path/to/file"] or File["concat_/path/to/file"]
|
# - The final file can be referened as File["/path/to/file"] or File["concat_/path/to/file"]
|
||||||
define concat($mode = 0644, $owner = $::id, $group = $concat::setup::root_group, $warn = "false", $force = "false", $backup = "puppet", $gnu = undef, $order="alpha") {
|
define concat($mode = '0644', $owner = $::id, $group = $concat::setup::root_group, $warn = false, $force = false, $backup = 'puppet', $gnu = undef, $order='alpha') {
|
||||||
$safe_name = regsubst($name, '/', '_', 'G')
|
$safe_name = regsubst($name, '/', '_', 'G')
|
||||||
$concatdir = $concat::setup::concatdir
|
$concatdir = $concat::setup::concatdir
|
||||||
$version = $concat::setup::majorversion
|
$version = $concat::setup::majorversion
|
||||||
$fragdir = "${concatdir}/${safe_name}"
|
$fragdir = "${concatdir}/${safe_name}"
|
||||||
$concat_name = "fragments.concat.out"
|
$concat_name = 'fragments.concat.out'
|
||||||
$default_warn_message = '# This file is managed by Puppet. DO NOT EDIT.'
|
$default_warn_message = '# This file is managed by Puppet. DO NOT EDIT.'
|
||||||
|
|
||||||
case $warn {
|
case $warn {
|
||||||
'true',true,yes,on: { $warnmsg = "$default_warn_message" }
|
'true',true,yes,on: { $warnmsg = $default_warn_message }
|
||||||
'false',false,no,off: { $warnmsg = "" }
|
'false',false,no,off: { $warnmsg = '' }
|
||||||
default: { $warnmsg = "$warn" }
|
default: { $warnmsg = $warn }
|
||||||
}
|
}
|
||||||
|
|
||||||
$warnmsg_escaped = regsubst($warnmsg, "'", "'\\\\''", 'G')
|
$warnmsg_escaped = regsubst($warnmsg, "'", "'\\\\''", 'G')
|
||||||
$warnflag = $warnmsg_escaped ? {
|
$warnflag = $warnmsg_escaped ? {
|
||||||
'' => '',
|
'' => '',
|
||||||
default => "-w '$warnmsg_escaped'"
|
default => "-w '${warnmsg_escaped}'"
|
||||||
}
|
}
|
||||||
|
|
||||||
case $force {
|
case $force {
|
||||||
'true',true,yes,on: { $forceflag = "-f" }
|
'true',true,yes,on: { $forceflag = '-f' }
|
||||||
'false',false,no,off: { $forceflag = "" }
|
'false',false,no,off: { $forceflag = '' }
|
||||||
default: { fail("Improper 'force' value given to concat: $force") }
|
default: { fail("Improper 'force' value given to concat: ${force}") }
|
||||||
}
|
}
|
||||||
|
|
||||||
case $order {
|
case $order {
|
||||||
numeric: { $orderflag = "-n" }
|
numeric: { $orderflag = '-n' }
|
||||||
alpha: { $orderflag = "" }
|
alpha: { $orderflag = '' }
|
||||||
default: { fail("Improper 'order' value given to concat: $order") }
|
default: { fail("Improper 'order' value given to concat: ${order}") }
|
||||||
}
|
}
|
||||||
|
|
||||||
File{
|
File{
|
||||||
owner => $::id,
|
owner => $::id,
|
||||||
group => $group,
|
group => $group,
|
||||||
mode => $mode,
|
mode => $mode,
|
||||||
backup => $backup
|
backup => $backup
|
||||||
}
|
}
|
||||||
|
|
||||||
file{$fragdir:
|
file{$fragdir:
|
||||||
ensure => directory;
|
ensure => directory;
|
||||||
|
|
||||||
"${fragdir}/fragments":
|
"${fragdir}/fragments":
|
||||||
ensure => directory,
|
ensure => directory,
|
||||||
recurse => true,
|
recurse => true,
|
||||||
purge => true,
|
purge => true,
|
||||||
force => true,
|
force => true,
|
||||||
ignore => [".svn", ".git", ".gitignore"],
|
ignore => ['.svn', '.git', '.gitignore'],
|
||||||
source => $version ? {
|
source => $version ? {
|
||||||
24 => "puppet:///concat/null",
|
24 => 'puppet:///concat/null',
|
||||||
default => undef,
|
default => undef,
|
||||||
},
|
},
|
||||||
notify => Exec["concat_${name}"];
|
notify => Exec["concat_${name}"];
|
||||||
|
|
||||||
"${fragdir}/fragments.concat":
|
"${fragdir}/fragments.concat":
|
||||||
ensure => present;
|
ensure => present;
|
||||||
|
|
||||||
"${fragdir}/${concat_name}":
|
"${fragdir}/${concat_name}":
|
||||||
ensure => present;
|
ensure => present;
|
||||||
|
|
||||||
$name:
|
$name:
|
||||||
source => "${fragdir}/${concat_name}",
|
ensure => present,
|
||||||
owner => $owner,
|
source => "${fragdir}/${concat_name}",
|
||||||
group => $group,
|
owner => $owner,
|
||||||
checksum => md5,
|
group => $group,
|
||||||
mode => $mode,
|
checksum => md5,
|
||||||
ensure => present,
|
mode => $mode,
|
||||||
alias => "concat_${name}";
|
alias => "concat_${name}";
|
||||||
}
|
}
|
||||||
|
|
||||||
exec{"concat_${name}":
|
exec{"concat_${name}":
|
||||||
notify => File[$name],
|
notify => File[$name],
|
||||||
subscribe => File[$fragdir],
|
subscribe => File[$fragdir],
|
||||||
alias => "concat_${fragdir}",
|
alias => "concat_${fragdir}",
|
||||||
require => [ File[$fragdir], File["${fragdir}/fragments"], File["${fragdir}/fragments.concat"] ],
|
require => [ File[$fragdir], File["${fragdir}/fragments"], File["${fragdir}/fragments.concat"] ],
|
||||||
unless => "${concat::setup::concatdir}/bin/concatfragments.sh -o ${fragdir}/${concat_name} -d ${fragdir} -t ${warnflag} ${forceflag} ${orderflag}",
|
unless => "${concat::setup::concatdir}/bin/concatfragments.sh -o ${fragdir}/${concat_name} -d ${fragdir} -t ${warnflag} ${forceflag} ${orderflag}",
|
||||||
command => "${concat::setup::concatdir}/bin/concatfragments.sh -o ${fragdir}/${concat_name} -d ${fragdir} ${warnflag} ${forceflag} ${orderflag}",
|
command => "${concat::setup::concatdir}/bin/concatfragments.sh -o ${fragdir}/${concat_name} -d ${fragdir} ${warnflag} ${forceflag} ${orderflag}",
|
||||||
}
|
}
|
||||||
if $::id == 'root' {
|
if $::id == 'root' {
|
||||||
Exec["concat_${name}"]{
|
Exec["concat_${name}"]{
|
||||||
user => root,
|
user => root,
|
||||||
group => $group,
|
group => $group,
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,33 +13,31 @@
|
||||||
#
|
#
|
||||||
# It also copies out the concatfragments.sh file to ${concatdir}/bin
|
# It also copies out the concatfragments.sh file to ${concatdir}/bin
|
||||||
class concat::setup {
|
class concat::setup {
|
||||||
$id = $::id
|
$id = $::id
|
||||||
$root_group = $id ? {
|
$root_group = $id ? {
|
||||||
root => 0,
|
root => 0,
|
||||||
default => $id
|
default => $id
|
||||||
}
|
}
|
||||||
$concatdir = $::concat_basedir
|
$concatdir = $::concat_basedir
|
||||||
$majorversion = regsubst($::puppetversion, '^[0-9]+[.]([0-9]+)[.][0-9]+$', '\1')
|
$majorversion = regsubst($::puppetversion, '^[0-9]+[.]([0-9]+)[.][0-9]+$', '\1')
|
||||||
|
|
||||||
file{"${concatdir}/bin/concatfragments.sh":
|
file{"${concatdir}/bin/concatfragments.sh":
|
||||||
owner => $id,
|
owner => $id,
|
||||||
group => $root_group,
|
group => $root_group,
|
||||||
mode => 755,
|
mode => '0755',
|
||||||
source => $majorversion ? {
|
source => $majorversion ? {
|
||||||
24 => "puppet:///concat/concatfragments.sh",
|
24 => 'puppet:///concat/concatfragments.sh',
|
||||||
default => "puppet:///modules/concat/concatfragments.sh"
|
default => 'puppet:///modules/concat/concatfragments.sh'
|
||||||
};
|
};
|
||||||
|
|
||||||
[ $concatdir, "${concatdir}/bin" ]:
|
[ $concatdir, "${concatdir}/bin" ]:
|
||||||
ensure => directory,
|
ensure => directory,
|
||||||
owner => $id,
|
owner => $id,
|
||||||
group => $root_group,
|
group => $root_group,
|
||||||
mode => '0750';
|
mode => '0750';
|
||||||
|
|
||||||
## Old versions of this module used a different path.
|
## Old versions of this module used a different path.
|
||||||
'/usr/local/bin/concatfragments.sh':
|
'/usr/local/bin/concatfragments.sh':
|
||||||
ensure => absent;
|
ensure => absent;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
# vi:tabstop=4:expandtab:ai
|
|
||||||
|
|
Loading…
Reference in a new issue