]> git.donarmstrong.com Git - dsa-puppet.git/blob - 3rdparty/modules/concat/manifests/init.pp
try if downgrading to 1.2.2 solves my problem
[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 # [*force*]
20 #   Enables creating empty files if no fragments are present
21 # [*warn*]
22 #   Adds a normal shell style comment top of the file indicating that it is
23 #   built by puppet
24 # [*force*]
25 # [*backup*]
26 #   Controls the filebucketing behavior of the final file and see File type
27 #   reference for its use.  Defaults to 'puppet'
28 # [*replace*]
29 #   Whether to replace a file that already exists on the local system
30 # [*order*]
31 # [*ensure_newline*]
32 # [*gnu*]
33 #   Deprecated
34 #
35 # === Actions:
36 # * Creates fragment directories if it didn't exist already
37 # * Executes the concatfragments.rb script to build the final file, this
38 #   script will create directory/fragments.concat.   Execution happens only
39 #   when:
40 #   * The directory changes
41 #   * fragments.concat != final destination, this means rebuilds will happen
42 #     whenever someone changes or deletes the final file.  Checking is done
43 #     using /usr/bin/cmp.
44 #   * The Exec gets notified by something else - like the concat::fragment
45 #     define
46 # * Copies the file over to the final destination using a file resource
47 #
48 # === Aliases:
49 #
50 # * The exec can notified using Exec["concat_/path/to/file"] or
51 #   Exec["concat_/path/to/directory"]
52 # * The final file can be referenced as File["/path/to/file"] or
53 #   File["concat_/path/to/file"]
54 #
55 define concat(
56   $ensure         = 'present',
57   $path           = $name,
58   $owner          = undef,
59   $group          = undef,
60   $mode           = '0644',
61   $warn           = false,
62   $force          = false,
63   $backup         = 'puppet',
64   $replace        = true,
65   $order          = 'alpha',
66   $ensure_newline = false,
67   $validate_cmd   = undef,
68   $gnu            = undef
69 ) {
70   validate_re($ensure, '^present$|^absent$')
71   validate_absolute_path($path)
72   validate_string($owner)
73   validate_string($group)
74   validate_string($mode)
75   if ! (is_string($warn) or $warn == true or $warn == false) {
76     fail('$warn is not a string or boolean')
77   }
78   validate_bool($force)
79   if ! concat_is_bool($backup) and ! is_string($backup) {
80     fail('$backup must be string or bool!')
81   }
82   validate_bool($replace)
83   validate_re($order, '^alpha$|^numeric$')
84   validate_bool($ensure_newline)
85   if $validate_cmd and ! is_string($validate_cmd) {
86     fail('$validate_cmd must be a string')
87   }
88   if $gnu {
89     warning('The $gnu parameter to concat is deprecated and has no effect')
90   }
91
92   include concat::setup
93
94   $safe_name            = regsubst($name, '[/:]', '_', 'G')
95   $concatdir            = $concat::setup::concatdir
96   $fragdir              = "${concatdir}/${safe_name}"
97   $concat_name          = 'fragments.concat.out'
98   $script_command       = $concat::setup::script_command
99   $default_warn_message = '# This file is managed by Puppet. DO NOT EDIT.'
100   $bool_warn_message    = 'Using stringified boolean values (\'true\', \'yes\', \'on\', \'false\', \'no\', \'off\') to represent boolean true/false as the $warn parameter to concat is deprecated and will be treated as the warning message in a future release'
101
102   case $warn {
103     true: {
104       $warn_message = $default_warn_message
105     }
106     'true', 'yes', 'on': {
107       warning($bool_warn_message)
108       $warn_message = $default_warn_message
109     }
110     false: {
111       $warn_message = ''
112     }
113     'false', 'no', 'off': {
114       warning($bool_warn_message)
115       $warn_message = ''
116     }
117     default: {
118       $warn_message = $warn
119     }
120   }
121
122   $warnmsg_escaped = regsubst($warn_message, '\'', '\'\\\'\'', 'G')
123   $warnflag = $warnmsg_escaped ? {
124     ''      => '',
125     default => "-w '${warnmsg_escaped}'"
126   }
127
128   $forceflag = $force ? {
129     true  => '-f',
130     false => '',
131   }
132
133   $orderflag = $order ? {
134     'numeric' => '-n',
135     'alpha'   => '',
136   }
137
138   $newlineflag = $ensure_newline ? {
139     true  => '-l',
140     false => '',
141   }
142
143   File {
144     backup  => $backup,
145   }
146
147   # reset poisoned Exec defaults
148   Exec {
149     user  => undef,
150     group => undef,
151   }
152
153   if $ensure == 'present' {
154     file { $fragdir:
155       ensure => directory,
156       mode   => '0750',
157     }
158
159     file { "${fragdir}/fragments":
160       ensure  => directory,
161       mode    => '0750',
162       force   => true,
163       ignore  => ['.svn', '.git', '.gitignore'],
164       notify  => Exec["concat_${name}"],
165       purge   => true,
166       recurse => true,
167     }
168
169     file { "${fragdir}/fragments.concat":
170       ensure => present,
171       mode   => '0640',
172     }
173
174     file { "${fragdir}/${concat_name}":
175       ensure => present,
176       mode   => '0640',
177     }
178
179     file { $name:
180       ensure       => present,
181       owner        => $owner,
182       group        => $group,
183       mode         => $mode,
184       replace      => $replace,
185       path         => $path,
186       alias        => "concat_${name}",
187       source       => "${fragdir}/${concat_name}",
188       backup       => $backup,
189     }
190
191     # Only newer versions of puppet 3.x support the validate_cmd parameter
192     if $validate_cmd {
193       File[$name] {
194         validate_cmd => $validate_cmd,
195       }
196     }
197
198     # remove extra whitespace from string interpolation to make testing easier
199     $command = strip(regsubst("${script_command} -o \"${fragdir}/${concat_name}\" -d \"${fragdir}\" ${warnflag} ${forceflag} ${orderflag} ${newlineflag}", '\s+', ' ', 'G'))
200
201     # make sure ruby is in the path for PE
202     if defined('$is_pe') and $::is_pe {
203       if $::kernel == 'windows' {
204         $command_path = "${::env_windows_installdir}/bin:${::path}"
205       } else {
206         $command_path = "/opt/puppet/bin:${::path}"
207       }
208     } else {
209       $command_path = $::path
210     }
211
212     # if puppet is running as root, this exec should also run as root to allow
213     # the concatfragments.rb script to potentially be installed in path that
214     # may not be accessible by a target non-root owner.
215     exec { "concat_${name}":
216       alias     => "concat_${fragdir}",
217       command   => $command,
218       notify    => File[$name],
219       subscribe => File[$fragdir],
220       unless    => "${command} -t",
221       path      => $command_path,
222       require   => [
223         File[$fragdir],
224         File["${fragdir}/fragments"],
225         File["${fragdir}/fragments.concat"],
226       ],
227     }
228   } else {
229     file { [
230       $fragdir,
231       "${fragdir}/fragments",
232       "${fragdir}/fragments.concat",
233       "${fragdir}/${concat_name}"
234     ]:
235       ensure => absent,
236       force  => true,
237     }
238
239     file { $path:
240       ensure => absent,
241       backup => $backup,
242     }
243
244     $absent_exec_command = $::kernel ? {
245       'windows' => 'cmd.exe /c exit 0',
246       default   => 'true',
247     }
248
249     $absent_exec_path = $::kernel ? {
250       'windows' => $::path,
251       default   => '/bin:/usr/bin',
252     }
253
254     # Need to have an unless here for idempotency.
255     exec { "concat_${name}":
256       alias   => "concat_${fragdir}",
257       command => $absent_exec_command,
258       unless  => $absent_exec_command,
259       path    => $absent_exec_path,
260     }
261   }
262 }
263
264 # vim:sw=2:ts=2:expandtab:textwidth=79