0a19b344f0e889a9de705f0aa70b1682158172f8
[mirror/dsa-puppet.git] / 3rdparty / modules / concat / manifests / init.pp
1 # Sets up so that you can use fragments to build a final config file,
2 #
3 # @param ensure
4 #   Present/Absent
5 # @param path
6 #   The path to the final file. Use this in case you want to differentiate
7 #   between the name of a resource and the file path.  Note: Use the name you
8 #   provided in the target of your fragments.
9 # @param owner
10 #   Who will own the file
11 # @param group
12 #   Who will own the file
13 # @param mode
14 #   The mode of the final file
15 # @param show_diff
16 #   Use metaparam for files to show/hide diffs for reporting when using eyaml
17 #   secrets.  Defaults to true
18 # @param warn
19 #   Adds a normal shell style comment top of the file indicating that it is
20 #   built by puppet.
21 #   Before 2.0.0, this parameter would add a newline at the end of the warn
22 #   message. To improve flexibilty, this was removed. Please add it explicitely
23 #   if you need it.
24 # @param backup
25 #   Controls the filebucketing behavior of the final file and see File type
26 #   reference for its use.  Defaults to 'puppet'
27 # @param replace
28 #   Whether to replace a file that already exists on the local system
29 # @param order
30 #   Select whether to order associated fragments by 'alpha' or 'numeric'.
31 #   Defaults to 'alpha'.
32 # @param ensure_newline
33 #   Specifies whether to ensure there's a new line at the end of each fragment.
34 #   Valid options: 'true' and 'false'. Default value: 'false'.
35 # @param selinux_ignore_defaults
36 # @param selrange
37 # @param selrole
38 # @param seltype
39 # @param seluser
40 # @param validate_cmd
41 #   Specifies a validation command to apply to the destination file.
42 #   Requires Puppet version 3.5 or newer. Valid options: a string to be passed
43 #   to a file resource. Default value: undefined.
44 #
45 define concat(
46   Enum['present', 'absent']          $ensure                  = 'present',
47   Stdlib::Absolutepath               $path                    = $name,
48   Optional[Variant[String, Integer]] $owner                   = undef,
49   Optional[Variant[String, Integer]] $group                   = undef,
50   String                             $mode                    = '0644',
51   Variant[Boolean, String]           $warn                    = false,
52   Boolean                            $show_diff               = true,
53   Variant[Boolean, String]           $backup                  = 'puppet',
54   Boolean                            $replace                 = true,
55   Enum['alpha','numeric']            $order                   = 'alpha',
56   Boolean                            $ensure_newline          = false,
57   Optional[String]                   $validate_cmd            = undef,
58   Optional[Boolean]                  $selinux_ignore_defaults = undef,
59   Optional[String]                   $selrange                = undef,
60   Optional[String]                   $selrole                 = undef,
61   Optional[String]                   $seltype                 = undef,
62   Optional[String]                   $seluser                 = undef,
63 ) {
64
65   $safe_name            = regsubst($name, '[/:~\n\s\+\*\(\)@]', '_', 'G')
66   $default_warn_message = "# This file is managed by Puppet. DO NOT EDIT.\n"
67
68   case $warn {
69     true: {
70       $warn_message = $default_warn_message
71       $_append_header = true
72     }
73     false: {
74       $warn_message = ''
75       $_append_header = false
76     }
77     default: {
78       $warn_message = $warn
79       $_append_header = true
80     }
81   }
82
83   if $ensure == 'present' {
84     concat_file { $name:
85       tag                     => $safe_name,
86       path                    => $path,
87       owner                   => $owner,
88       group                   => $group,
89       mode                    => $mode,
90       selinux_ignore_defaults => $selinux_ignore_defaults,
91       selrange                => $selrange,
92       selrole                 => $selrole,
93       seltype                 => $seltype,
94       seluser                 => $seluser,
95       replace                 => $replace,
96       backup                  => $backup,
97       show_diff               => $show_diff,
98       order                   => $order,
99       ensure_newline          => $ensure_newline,
100       validate_cmd            => $validate_cmd,
101     }
102
103     if $_append_header {
104       concat_fragment { "${name}_header":
105         target  => $name,
106         tag     => $safe_name,
107         content => $warn_message,
108         order   => '0',
109       }
110     }
111   } else {
112     concat_file { $name:
113       ensure => $ensure,
114       tag    => $safe_name,
115       path   => $path,
116       backup => $backup,
117     }
118   }
119 }