2013-05-09 21:24:22 +02:00
# = = Define: concat: : fragment
#
2010-05-06 23:55:02 +02:00
# Puts a file fragment into a directory previous setup using concat
2012-08-14 17:13:25 +02:00
#
2013-05-09 21:24:22 +02:00
# = = = Options:
#
# [ * target* ]
# The file that these fragments belong to
# [ * content* ]
# If present puts the content into the file
# [ * source* ]
# If content was not specified, use the source
# [ * order* ]
# By default all files gets a 1 0 _ prefix in the directory you can set it to
# anything else using this to influence the order of the content in the file
# [ * ensure* ]
# Present/ Absent or destination to a file to include another file
# [ * mode* ]
2013-11-02 18:45:02 +01:00
# Deprecated
2013-05-09 21:24:22 +02:00
# [ * owner* ]
2013-11-02 18:45:02 +01:00
# Deprecated
2013-05-09 21:24:22 +02:00
# [ * group* ]
2013-11-02 18:45:02 +01:00
# Deprecated
2013-05-09 21:24:22 +02:00
# [ * backup* ]
2013-10-29 23:39:54 +01:00
# Deprecated
2013-05-09 21:24:22 +02:00
#
define concat: : fragment(
$ target,
2013-10-22 17:53:18 +02:00
$c ontent = undef,
$ source = undef,
$ order = 1 0 ,
$e nsure = 'present' ,
2013-11-02 18:45:02 +01:00
$ mode = undef,
2013-10-24 17:48:37 +02:00
$ owner = undef,
2013-10-29 23:39:54 +01:00
$ group = undef,
$bac kup = undef
2013-10-15 23:07:51 +02:00
) {
2013-11-02 17:33:41 +01:00
validate_string( $ target)
2013-12-06 00:01:17 +01:00
if ! ( $e nsure in [ 'present' , 'absent' ] ) {
warning( 'Passing a value other than \' present\ ' or \' absent\ ' as the $ensure parameter to concat::fragment is deprecated. If you want to use the content of a file as a fragment please use the $source parameter.' )
}
2013-10-23 16:41:38 +02:00
validate_string( $c ontent)
2013-11-13 07:16:47 +01:00
if ! ( is_string( $ source) or is_array( $ source) ) {
fail( '$source is not a string or an Array.' )
}
2013-10-23 16:41:38 +02:00
validate_string( $ order)
2013-11-02 18:45:02 +01:00
if $ mode {
warning( 'The $mode parameter to concat::fragment is deprecated and has no effect' )
}
if $ owner {
warning( 'The $owner parameter to concat::fragment is deprecated and has no effect' )
}
if $ group {
warning( 'The $group parameter to concat::fragment is deprecated and has no effect' )
}
2013-10-29 23:39:54 +01:00
if $bac kup {
warning( 'The $backup parameter to concat::fragment is deprecated and has no effect' )
}
2013-10-23 16:41:38 +02:00
2013-10-15 23:07:51 +02:00
include concat: : setup
2013-09-02 13:49:40 +02:00
$ safe_name = regsubst( $ name , '[/:\n]' , '_' , 'GM' )
$ safe_target_name = regsubst( $ target, '[/:\n]' , '_' , 'GM' )
2013-10-22 17:53:18 +02:00
$c oncatdir = $c oncat: : setup: : concatdir
$f ragdir = "${concatdir}/${safe_target_name}"
2010-05-06 23:55:02 +02:00
2013-12-06 00:01:17 +01:00
# The file type ' s semantics are problematic in that ensure = > present will
# not over write a pre- existing symlink. We are attempting to provide
# backwards compatiblity with previous concat: : fragment versions that
# supported the file type ' s ensure = > / target syntax
# be paranoid and only allow the fragment's file resource' s ensure param to
# be file , absent, or a file target
$ safe_ensure = $e nsure ? {
'' = > 'file' ,
undef = > 'file' ,
'file' = > 'file' ,
'present' = > 'file' ,
'absent' = > 'absent' ,
default = > $e nsure,
}
# if it looks line ensure = > / target syntax was used, fish that out
if ! ( $e nsure in [ '' , 'present' , 'absent' , 'file' ] ) {
$e nsure_target = $e nsure
}
# the file type ' s semantics only allows one of : ensure = > / target, content,
# or source
if ( $e nsure_target and $ source) or
( $e nsure_target and $c ontent) or
( $ source and $c ontent) {
fail( 'You cannot specify more than one of $content, $source, $ensure => /target' )
}
if ! ( $c ontent or $ source or $e nsure_target) {
crit( 'No content, source or symlink specified' )
2012-03-14 18:02:43 +01:00
}
2010-05-06 23:55:02 +02:00
2013-11-02 18:45:02 +01:00
# punt on group ownership until some point in the distant future when $ : : gid
# can be relied on to be present
2013-10-22 17:53:18 +02:00
file { "${fragdir} / fragments/ $ {order} _${safe_name} " :
2013-12-06 00:01:17 +01:00
ensure = > $ safe_ensure,
2013-11-02 18:45:02 +01:00
owner = > $ : : id,
mode = > '0640' ,
2013-02-28 13:00:11 +01:00
source = > $ source,
content = > $c ontent,
2013-10-24 00:42:44 +02:00
backup = > false ,
2013-02-28 13:00:11 +01:00
alias = > "concat_fragment_${name}" ,
notify = > Exec[ "concat_${target}" ]
2012-03-14 18:02:43 +01:00
}
2010-05-06 23:55:02 +02:00
}