|
1 | 1 | # == Define: concat::fragment |
2 | 2 | # |
3 | | -# Puts a file fragment into a directory previous setup using concat |
| 3 | +# Creates a file_fragment in the catalogue |
4 | 4 | # |
5 | 5 | # === Options: |
6 | 6 | # |
|
13 | 13 | # [*order*] |
14 | 14 | # By default all files gets a 10_ prefix in the directory you can set it to |
15 | 15 | # anything else using this to influence the order of the content in the file |
16 | | -# [*ensure*] |
17 | | -# Present/Absent or destination to a file to include another file |
18 | | -# [*mode*] |
19 | | -# Deprecated |
20 | | -# [*owner*] |
21 | | -# Deprecated |
22 | | -# [*group*] |
23 | | -# Deprecated |
24 | | -# [*backup*] |
25 | | -# Deprecated |
26 | 16 | # |
27 | 17 | define concat::fragment( |
28 | 18 | $target, |
29 | 19 | $content = undef, |
30 | 20 | $source = undef, |
31 | 21 | $order = '10', |
32 | | - $ensure = undef, |
33 | | - $mode = undef, |
34 | | - $owner = undef, |
35 | | - $group = undef, |
36 | | - $backup = undef |
37 | 22 | ) { |
38 | 23 | validate_string($target) |
39 | 24 | validate_string($content) |
40 | 25 | if !(is_string($source) or is_array($source)) { |
41 | 26 | fail('$source is not a string or an Array.') |
42 | 27 | } |
| 28 | + |
43 | 29 | if !(is_string($order) or is_integer($order)) { |
44 | 30 | fail('$order is not a string or integer.') |
45 | 31 | } elsif (is_string($order) and $order =~ /[:\n\/]/) { |
46 | 32 | fail("Order cannot contain '/', ':', or '\n'.") |
47 | 33 | } |
48 | | - if $mode { |
49 | | - warning('The $mode parameter to concat::fragment is deprecated and has no effect') |
50 | | - } |
51 | | - if $owner { |
52 | | - warning('The $owner parameter to concat::fragment is deprecated and has no effect') |
53 | | - } |
54 | | - if $group { |
55 | | - warning('The $group parameter to concat::fragment is deprecated and has no effect') |
56 | | - } |
57 | | - if $backup { |
58 | | - warning('The $backup parameter to concat::fragment is deprecated and has no effect') |
59 | | - } |
60 | | - $my_backup = concat_getparam(Concat[$target], 'backup') |
61 | | - if $ensure == undef { |
62 | | - $my_ensure = concat_getparam(Concat[$target], 'ensure') |
63 | | - } else { |
64 | | - if ! ($ensure in [ 'present', 'absent' ]) { |
65 | | - 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.') |
66 | | - } |
67 | | - $my_ensure = $ensure |
68 | | - } |
69 | | - |
70 | | - include concat::setup |
71 | | - |
72 | | - $safe_name = regsubst($name, '[/:\n]', '_', 'GM') |
73 | | - $safe_target_name = regsubst($target, '[/:\n]', '_', 'GM') |
74 | | - $concatdir = $concat::setup::concatdir |
75 | | - $fragdir = "${concatdir}/${safe_target_name}" |
76 | | - $fragowner = $concat::setup::fragment_owner |
77 | | - $fraggroup = $concat::setup::fragment_group |
78 | | - $fragmode = $concat::setup::fragment_mode |
79 | | - |
80 | | - # The file type's semantics are problematic in that ensure => present will |
81 | | - # not over write a pre-existing symlink. We are attempting to provide |
82 | | - # backwards compatiblity with previous concat::fragment versions that |
83 | | - # supported the file type's ensure => /target syntax |
84 | | - |
85 | | - # be paranoid and only allow the fragment's file resource's ensure param to |
86 | | - # be file, absent, or a file target |
87 | | - $safe_ensure = $my_ensure ? { |
88 | | - '' => 'file', |
89 | | - undef => 'file', |
90 | | - 'file' => 'file', |
91 | | - 'present' => 'file', |
92 | | - 'absent' => 'absent', |
93 | | - default => $my_ensure, |
94 | | - } |
95 | 34 |
|
96 | | - # if it looks line ensure => /target syntax was used, fish that out |
97 | | - if ! ($my_ensure in ['', 'present', 'absent', 'file' ]) { |
98 | | - $ensure_target = $my_ensure |
99 | | - } else { |
100 | | - $ensure_target = undef |
101 | | - } |
102 | | - |
103 | | - # the file type's semantics only allows one of: ensure => /target, content, |
104 | | - # or source |
105 | | - if ($ensure_target and $source) or |
106 | | - ($ensure_target and $content) or |
107 | | - ($source and $content) { |
108 | | - fail('You cannot specify more than one of $content, $source, $ensure => /target') |
109 | | - } |
110 | | - |
111 | | - if ! ($content or $source or $ensure_target) { |
| 35 | + if ! ($content or $source) { |
112 | 36 | crit('No content, source or symlink specified') |
| 37 | + } elsif ($content and $source) { |
| 38 | + fail("Can't use 'source' and 'content' at the same time") |
113 | 39 | } |
114 | 40 |
|
115 | | - file { "${fragdir}/fragments/${order}_${safe_name}": |
116 | | - ensure => $safe_ensure, |
117 | | - owner => $fragowner, |
118 | | - group => $fraggroup, |
119 | | - mode => $fragmode, |
120 | | - source => $source, |
| 41 | + $safe_target_name = regsubst($target, '[/:\n\s]', '_', 'GM') |
| 42 | + |
| 43 | + file_fragment { $name: |
| 44 | + tag => $safe_target_name, |
| 45 | + order => $order, |
121 | 46 | content => $content, |
122 | | - backup => $my_backup, |
123 | | - replace => true, |
124 | | - alias => "concat_fragment_${name}", |
125 | | - notify => Exec["concat_${target}"] |
| 47 | + source => $source, |
126 | 48 | } |
127 | 49 | } |
0 commit comments