1 # == Define: concat::fragment
3 # Puts a file fragment into a directory previous setup using concat
8 # The file that these fragments belong to
10 # If present puts the content into the file
12 # If content was not specified, use the source
14 # By default all files gets a 10_ prefix in the directory you can set it to
15 # anything else using this to influence the order of the content in the file
17 # Present/Absent or destination to a file to include another file
27 define concat::fragment(
38 validate_string($target)
39 validate_string($content)
40 if !(is_string($source) or is_array($source)) {
41 fail('$source is not a string or an Array.')
43 if !(is_string($order) or is_integer($order)) {
44 fail('$order is not a string or integer.')
45 } elsif (is_string($order) and $order =~ /[:\n\/]/) {
46 fail("Order cannot contain '/', ':', or '\n'.")
49 warning('The $mode parameter to concat::fragment is deprecated and has no effect')
52 warning('The $owner parameter to concat::fragment is deprecated and has no effect')
55 warning('The $group parameter to concat::fragment is deprecated and has no effect')
58 warning('The $backup parameter to concat::fragment is deprecated and has no effect')
61 $my_backup = concat_getparam(Concat[$target], 'backup')
62 $_backup = $my_backup ? {
68 $my_ensure = concat_getparam(Concat[$target], 'ensure')
70 if ! ($ensure in [ 'present', 'absent' ]) {
71 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.')
78 $safe_name = regsubst($name, '[/:\n]', '_', 'GM')
79 $safe_target_name = regsubst($target, '[/:\n]', '_', 'GM')
80 $concatdir = $concat::setup::concatdir
81 $fragdir = "${concatdir}/${safe_target_name}"
82 $fragowner = $concat::setup::fragment_owner
83 $fraggroup = $concat::setup::fragment_group
84 $fragmode = $concat::setup::fragment_mode
86 # The file type's semantics are problematic in that ensure => present will
87 # not over write a pre-existing symlink. We are attempting to provide
88 # backwards compatiblity with previous concat::fragment versions that
89 # supported the file type's ensure => /target syntax
91 # be paranoid and only allow the fragment's file resource's ensure param to
92 # be file, absent, or a file target
93 $safe_ensure = $my_ensure ? {
99 default => $my_ensure,
102 # if it looks line ensure => /target syntax was used, fish that out
103 if ! ($my_ensure in ['', 'present', 'absent', 'file' ]) {
104 $ensure_target = $my_ensure
106 $ensure_target = undef
109 # the file type's semantics only allows one of: ensure => /target, content,
111 if ($ensure_target and $source) or
112 ($ensure_target and $content) or
113 ($source and $content) {
114 fail('You cannot specify more than one of $content, $source, $ensure => /target')
117 if ! ($content or $source or $ensure_target) {
118 crit('No content, source or symlink specified')
121 file { "${fragdir}/fragments/${order}_${safe_name}":
122 ensure => $safe_ensure,
130 alias => "concat_fragment_${name}",
131 notify => Exec["concat_${target}"]