X-Git-Url: https://git.adam-barratt.org.uk/?a=blobdiff_plain;f=3rdparty%2Fmodules%2Fconcat%2Fmanifests%2Ffragment.pp;h=8d9a0a00ccdcc7936ee4299e0db96f0a0ce2fb1f;hb=30caaa85aed7015ca0d77216bff175eebd917eb7;hp=7b13b004255216c3c6e7747bec386f445c9e3576;hpb=917f80937c03a7f486d25fa70373f1f4d4b02958;p=mirror%2Fdsa-puppet.git diff --git a/3rdparty/modules/concat/manifests/fragment.pp b/3rdparty/modules/concat/manifests/fragment.pp index 7b13b0042..8d9a0a00c 100644 --- a/3rdparty/modules/concat/manifests/fragment.pp +++ b/3rdparty/modules/concat/manifests/fragment.pp @@ -1,133 +1,45 @@ -# == Define: concat::fragment +# @summary +# Manages a fragment of text to be compiled into a file. # -# Puts a file fragment into a directory previous setup using concat +# @param content +# Supplies the content of the fragment. Note: You must supply either a content parameter or a source parameter. # -# === Options: +# @param order +# Reorders your fragments within the destination file. Fragments that share the same order number are ordered by name. The string +# option is recommended. # -# [*target*] -# The file that these fragments belong to -# [*content*] -# If present puts the content into the file -# [*source*] -# If content was not specified, use the source -# [*order*] -# By default all files gets a 10_ prefix in the directory you can set it to -# anything else using this to influence the order of the content in the file -# [*ensure*] -# Present/Absent or destination to a file to include another file -# [*mode*] -# Deprecated -# [*owner*] -# Deprecated -# [*group*] -# Deprecated -# [*backup*] -# Deprecated +# @param source +# Specifies a file to read into the content of the fragment. Note: You must supply either a content parameter or a source parameter. +# Valid options: a string or an array, containing one or more Puppet URLs. +# +# @param target +# Specifies the destination file of the fragment. Valid options: a string containing the path or title of the parent concat resource. # define concat::fragment( - $target, - $content = undef, - $source = undef, - $order = '10', - $ensure = undef, - $mode = undef, - $owner = undef, - $group = undef, - $backup = undef + String $target, + Optional[String] $content = undef, + Optional[Variant[String, Array]] $source = undef, + Variant[String, Integer] $order = '10', ) { - validate_string($target) - validate_string($content) - if !(is_string($source) or is_array($source)) { - fail('$source is not a string or an Array.') - } - if !(is_string($order) or is_integer($order)) { - fail('$order is not a string or integer.') - } elsif (is_string($order) and $order =~ /[:\n\/]/) { - fail("Order cannot contain '/', ':', or '\n'.") - } - if $mode { - warning('The $mode parameter to concat::fragment is deprecated and has no effect') - } - if $owner { - warning('The $owner parameter to concat::fragment is deprecated and has no effect') - } - if $group { - warning('The $group parameter to concat::fragment is deprecated and has no effect') - } - if $backup { - warning('The $backup parameter to concat::fragment is deprecated and has no effect') - } - - $my_backup = concat_getparam(Concat[$target], 'backup') - $_backup = $my_backup ? { - '' => undef, - default => $my_backup - } + $resource = 'Concat::Fragment' - if $ensure == undef { - $my_ensure = concat_getparam(Concat[$target], 'ensure') - } else { - if ! ($ensure in [ 'present', 'absent' ]) { - 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.') - } - $my_ensure = $ensure + if ($order =~ String and $order =~ /[:\n\/]/) { + fail(translate("%{_resource}['%{_title}']: 'order' cannot contain '/', ':', or '\\n'.", {'_resource' => $resource, '_title' => $title})) } - include concat::setup - - $safe_name = regsubst($name, '[/:\n]', '_', 'GM') - $safe_target_name = regsubst($target, '[/:\n]', '_', 'GM') - $concatdir = $concat::setup::concatdir - $fragdir = "${concatdir}/${safe_target_name}" - $fragowner = $concat::setup::fragment_owner - $fraggroup = $concat::setup::fragment_group - $fragmode = $concat::setup::fragment_mode - - # The file type's semantics are problematic in that ensure => present will - # not over write a pre-existing symlink. We are attempting to provide - # backwards compatiblity with previous concat::fragment versions that - # supported the file type's ensure => /target syntax - - # be paranoid and only allow the fragment's file resource's ensure param to - # be file, absent, or a file target - $safe_ensure = $my_ensure ? { - '' => 'file', - undef => 'file', - 'file' => 'file', - 'present' => 'file', - 'absent' => 'absent', - default => $my_ensure, - } - - # if it looks line ensure => /target syntax was used, fish that out - if ! ($my_ensure in ['', 'present', 'absent', 'file' ]) { - $ensure_target = $my_ensure - } else { - $ensure_target = undef - } - - # the file type's semantics only allows one of: ensure => /target, content, - # or source - if ($ensure_target and $source) or - ($ensure_target and $content) or - ($source and $content) { - fail('You cannot specify more than one of $content, $source, $ensure => /target') - } - - if ! ($content or $source or $ensure_target) { + if ! ($content or $source) { crit('No content, source or symlink specified') + } elsif ($content and $source) { + fail(translate("%{_resource}['%{_title}']: Can't use 'source' and 'content' at the same time.", {'_resource' => $resource, '_title' => $title})) } - file { "${fragdir}/fragments/${order}_${safe_name}": - ensure => $safe_ensure, - owner => $fragowner, - group => $fraggroup, - mode => $fragmode, - source => $source, + $safe_target_name = regsubst($target, '[\\\\/:~\n\s\+\*\(\)@]', '_', 'GM') + + concat_fragment { $name: + target => $target, + tag => $safe_target_name, + order => $order, content => $content, - backup => $_backup, - replace => true, - alias => "concat_fragment_${name}", - notify => Exec["concat_${target}"] + source => $source, } }