3 # Sets up so that you can use fragments to build a final config file,
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.
14 # Who will own the file
16 # Who will own the file
18 # The mode of the final file
20 # Enables creating empty files if no fragments are present
22 # Adds a normal shell style comment top of the file indicating that it is
26 # Controls the filebucketing behavior of the final file and see File type
27 # reference for its use. Defaults to 'puppet'
29 # Whether to replace a file that already exists on the local system
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
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
44 # * The Exec gets notified by something else - like the concat::fragment
46 # * Copies the file over to the final destination using a file resource
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"]
66 $ensure_newline = false,
67 $validate_cmd = undef,
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')
79 if ! concat_is_bool($backup) and ! is_string($backup) {
80 fail('$backup must be string or bool!')
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')
89 warning('The $gnu parameter to concat is deprecated and has no effect')
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'
104 $warn_message = $default_warn_message
106 'true', 'yes', 'on': {
107 warning($bool_warn_message)
108 $warn_message = $default_warn_message
113 'false', 'no', 'off': {
114 warning($bool_warn_message)
118 $warn_message = $warn
122 $warnmsg_escaped = regsubst($warn_message, '\'', '\'\\\'\'', 'G')
123 $warnflag = $warnmsg_escaped ? {
125 default => "-w '${warnmsg_escaped}'"
128 $forceflag = $force ? {
133 $orderflag = $order ? {
138 $newlineflag = $ensure_newline ? {
147 # reset poisoned Exec defaults
153 if $ensure == 'present' {
159 file { "${fragdir}/fragments":
163 ignore => ['.svn', '.git', '.gitignore'],
164 notify => Exec["concat_${name}"],
169 file { "${fragdir}/fragments.concat":
174 file { "${fragdir}/${concat_name}":
186 alias => "concat_${name}",
187 source => "${fragdir}/${concat_name}",
191 # Only newer versions of puppet 3.x support the validate_cmd parameter
194 validate_cmd => $validate_cmd,
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'))
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}"
206 $command_path = "/opt/puppet/bin:${::path}"
209 $command_path = $::path
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}",
218 notify => File[$name],
219 subscribe => File[$fragdir],
220 unless => "${command} -t",
221 path => $command_path,
224 File["${fragdir}/fragments"],
225 File["${fragdir}/fragments.concat"],
231 "${fragdir}/fragments",
232 "${fragdir}/fragments.concat",
233 "${fragdir}/${concat_name}"
244 $absent_exec_command = $::kernel ? {
245 'windows' => 'cmd.exe /c exit 0',
249 $absent_exec_path = $::kernel ? {
250 'windows' => $::path,
251 default => '/bin:/usr/bin',
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,
264 # vim:sw=2:ts=2:expandtab:textwidth=79