]> git.donarmstrong.com Git - dsa-puppet.git/blob - 3rdparty/modules/concat/manifests/init.pp
5bf53fc8354b1be9dc4c7f5b055fa82f8d7e35b6
[dsa-puppet.git] / 3rdparty / modules / concat / manifests / init.pp
1 # == Define: concat
2 #
3 # Sets up so that you can use fragments to build a final config file,
4 #
5 # === Options:
6 #
7 # [*ensure*]
8 #   Present/Absent
9 # [*path*]
10 #   The path to the final file. Use this in case you want to differentiate
11 #   between the name of a resource and the file path.  Note: Use the name you
12 #   provided in the target of your fragments.
13 # [*owner*]
14 #   Who will own the file
15 # [*group*]
16 #   Who will own the file
17 # [*mode*]
18 #   The mode of the final file
19 # [*warn*]
20 #   Adds a normal shell style comment top of the file indicating that it is
21 #   built by puppet
22 # [*backup*]
23 #   Controls the filebucketing behavior of the final file and see File type
24 #   reference for its use.  Defaults to 'puppet'
25 # [*replace*]
26 #   Whether to replace a file that already exists on the local system
27 # [*order*]
28 #   Select whether to order associated fragments by 'alpha' or 'numeric'.
29 #   Defaults to 'alpha'.
30 # [*ensure_newline*]
31 #   Specifies whether to ensure there's a new line at the end of each fragment.
32 #   Valid options: 'true' and 'false'. Default value: 'false'.
33 # [*validate_cmd*]
34 #   Specifies a validation command to apply to the destination file.
35 #   Requires Puppet version 3.5 or newer. Valid options: a string to be passed
36 #   to a file resource. Default value: undefined.
37 #
38
39 define concat(
40   $ensure         = 'present',
41   $path           = $name,
42   $owner          = undef,
43   $group          = undef,
44   $mode           = '0644',
45   $warn           = false,
46   $force          = undef,
47   $backup         = 'puppet',
48   $replace        = true,
49   $order          = 'alpha',
50   $ensure_newline = false,
51   $validate_cmd   = undef,
52 ) {
53   validate_re($ensure, '^present$|^absent$')
54   validate_absolute_path($path)
55   validate_string($owner)
56   validate_string($group)
57   validate_string($mode)
58   if ! (is_string($warn) or $warn == true or $warn == false) {
59     fail('$warn is not a string or boolean')
60   }
61   if ! is_bool($backup) and ! is_string($backup) {
62     fail('$backup must be string or bool!')
63   }
64   validate_bool($replace)
65   validate_re($order, '^alpha$|^numeric$')
66   validate_bool($ensure_newline)
67
68   if $validate_cmd and ! is_string($validate_cmd) {
69     fail('$validate_cmd must be a string')
70   }
71
72   if $force != undef {
73     warning('The $force parameter to concat is deprecated and has no effect.')
74   }
75
76   $safe_name            = regsubst($name, '[/:\n\s]', '_', 'G')
77   $default_warn_message = "# This file is managed by Puppet. DO NOT EDIT.\n"
78
79   case $warn {
80     true: {
81       $warn_message = $default_warn_message
82       $_append_header = true
83     }
84     false: {
85       $warn_message = ''
86       $_append_header = false
87     }
88     default: {
89       $warn_message = $warn
90       $_append_header = true
91     }
92   }
93
94   if $ensure == 'present' {
95     concat_file { $name:
96       tag            => $safe_name,
97       path           => $path,
98       owner          => $owner,
99       group          => $group,
100       mode           => $mode,
101       replace        => $replace,
102       backup         => $backup,
103       order          => $order,
104       ensure_newline => $ensure_newline,
105       validate_cmd   => $validate_cmd,
106     }
107
108     if $_append_header {
109       concat_fragment { "${name}_header":
110         tag     => $safe_name,
111         content => $warn_message,
112         order   => '0',
113       }
114     }
115   } else {
116     concat_file { $name:
117       ensure => $ensure,
118       tag    => $safe_name,
119       path   => $path,
120       backup => $backup,
121     }
122   }
123 }
124