forked from redhat-openstack/openstack-puppet-modules
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fragment.pp
55 lines (49 loc) · 1.41 KB
/
fragment.pp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# == Define: concat::fragment
#
# Creates a file_fragment in the catalogue
#
# === Options:
#
# [*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
#
define concat::fragment(
$target,
$ensure = undef,
$content = undef,
$source = undef,
$order = '10',
) {
validate_string($target)
if $ensure != undef {
warning('The $ensure parameter to concat::fragment is deprecated and has no effect.')
}
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 ! ($content or $source) {
crit('No content, source or symlink specified')
} elsif ($content and $source) {
fail("Can't use 'source' and 'content' at the same time")
}
$safe_target_name = regsubst($target, '[/:\n\s]', '_', 'GM')
file_fragment { $name:
tag => $safe_target_name,
order => $order,
content => $content,
source => $source,
}
}