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,
2014-05-22 01:06:37 +02:00
$ order = '10' ,
2014-01-21 22:28:42 +01:00
$e nsure = undef,
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-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.' )
}
2014-05-23 19:02:00 +02:00
if ! ( is_string( $ order) or is_integer( $ order) ) {
fail( '$order is not a string or integer.' )
}
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' )
}
2014-01-21 22:28:42 +01:00
if $e nsure = = undef {
2014-09-05 22:21:29 +02:00
$ my_ensure = concat_getparam( Concat[ $ target] , 'ensure' )
2014-01-21 22:28:42 +01:00
} else {
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.' )
}
2014-07-11 00:35:12 +02:00
$ my_ensure = $e nsure
2014-01-21 22:28:42 +01:00
}
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}"
2014-02-21 19:36:52 +01:00
$f ragowner = $c oncat: : setup: : fragment_owner
$f ragmode = $c oncat: : setup: : fragment_mode
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
2014-07-11 00:35:12 +02:00
$ safe_ensure = $ my_ensure ? {
2013-12-06 00:01:17 +01:00
'' = > 'file' ,
undef = > 'file' ,
'file' = > 'file' ,
'present' = > 'file' ,
'absent' = > 'absent' ,
2014-07-11 00:35:12 +02:00
default = > $ my_ensure,
2013-12-06 00:01:17 +01:00
}
# if it looks line ensure = > / target syntax was used, fish that out
2014-07-11 00:35:12 +02:00
if ! ( $ my_ensure in [ '' , 'present' , 'absent' , 'file' ] ) {
$e nsure_target = $ my_ensure
2014-02-25 14:54:09 +01:00
} else {
$e nsure_target = undef
2013-12-06 00:01:17 +01:00
}
# 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,
2014-02-21 19:36:52 +01:00
owner = > $f ragowner,
mode = > $f ragmode,
2013-02-28 13:00:11 +01:00
source = > $ source,
content = > $c ontent,
2013-10-24 00:42:44 +02:00
backup = > false ,
2014-08-02 01:18:16 +02:00
replace = > true ,
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
}