]> git.donarmstrong.com Git - dsa-puppet.git/blob - 3rdparty/modules/concat/manifests/fragment.pp
9cfae6613e23c10ef0d476a85fff9914e989bf37
[dsa-puppet.git] / 3rdparty / modules / concat / manifests / fragment.pp
1 # == Define: concat::fragment
2 #
3 # Creates a concat_fragment in the catalogue
4 #
5 # === Options:
6 #
7 # [*target*]
8 #   The file that these fragments belong to
9 # [*content*]
10 #   If present puts the content into the file
11 # [*source*]
12 #   If content was not specified, use the source
13 # [*order*]
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
16 #
17 define concat::fragment(
18     $target,
19     $ensure  = undef,
20     $content = undef,
21     $source  = undef,
22     $order   = '10',
23 ) {
24   validate_string($target)
25
26   if $ensure != undef {
27     warning('The $ensure parameter to concat::fragment is deprecated and has no effect.')
28   }
29
30   validate_string($content)
31   if !(is_string($source) or is_array($source)) {
32     fail('$source is not a string or an Array.')
33   }
34
35   if !(is_string($order) or is_integer($order)) {
36     fail('$order is not a string or integer.')
37   } elsif (is_string($order) and $order =~ /[:\n\/]/) {
38     fail("Order cannot contain '/', ':', or '\n'.")
39   }
40
41   if ! ($content or $source) {
42     crit('No content, source or symlink specified')
43   } elsif ($content and $source) {
44     fail("Can't use 'source' and 'content' at the same time")
45   }
46
47   $safe_target_name = regsubst($target, '[/:\n\s]', '_', 'GM')
48
49   concat_fragment { $name:
50     tag     => $safe_target_name,
51     order   => $order,
52     content => $content,
53     source  => $source,
54   }
55 }