28
|
1 |
# Definition: datacat |
|
2 |
# |
|
3 |
# This definition allows you to declare datacat managed files. |
|
4 |
# |
|
5 |
# Parameters: |
|
6 |
# All parameters are as for the file type, with the addition of a $template |
|
7 |
# parameter which is a path to a template to be used as the content of the |
|
8 |
# file. |
|
9 |
# |
|
10 |
# Sample Usage: |
|
11 |
# datacat { '/etc/motd': |
|
12 |
# owner => 'root', |
|
13 |
# group => 'root, |
|
14 |
# template => 'motd/motd.erb', |
|
15 |
# } |
|
16 |
# |
|
17 |
define datacat( |
|
18 |
$ensure = 'file', |
|
19 |
$template = undef, |
|
20 |
$template_body = undef, |
|
21 |
$collects = [], |
|
22 |
$backup = undef, |
|
23 |
$checksum = undef, |
|
24 |
$force = undef, |
|
25 |
$group = undef, |
|
26 |
$owner = undef, |
|
27 |
$mode = undef, |
|
28 |
$path = $title, |
|
29 |
$replace = undef, |
|
30 |
$selinux_ignore_defaults = undef, |
|
31 |
$selrange = undef, |
|
32 |
$selrole = undef, |
|
33 |
$seltype = undef, |
|
34 |
$seluser = undef, |
|
35 |
$show_diff = 'UNSET' |
|
36 |
) { |
|
37 |
if $show_diff != 'UNSET' { |
|
38 |
if versioncmp($settings::puppetversion, '3.2.0') >= 0 { |
|
39 |
File { show_diff => $show_diff } |
|
40 |
} else { |
|
41 |
warning('show_diff not supported in puppet prior to 3.2, ignoring') |
|
42 |
} |
|
43 |
} |
|
44 |
|
|
45 |
# we could validate ensure by simply passing it to file, but unfortunately |
|
46 |
# someone could try to be smart and pass 'directory', so we only allow a limited range |
|
47 |
if $ensure != 'absent' and $ensure != 'present' and $ensure != 'file' { |
|
48 |
fail("Datacat[${title}] invalid value for ensure") |
|
49 |
} |
|
50 |
|
|
51 |
if $ensure == 'absent' { |
|
52 |
file { $title: |
|
53 |
ensure => $ensure, |
|
54 |
path => $path, |
|
55 |
backup => $backup, |
|
56 |
force => $force, |
|
57 |
} |
|
58 |
} else { |
|
59 |
file { $title: |
|
60 |
path => $path, |
|
61 |
backup => $backup, |
|
62 |
checksum => $checksum, |
|
63 |
content => "To be replaced by datacat_collector[${title}]\n", |
|
64 |
force => $force, |
|
65 |
group => $group, |
|
66 |
mode => $mode, |
|
67 |
owner => $owner, |
|
68 |
replace => $replace, |
|
69 |
selinux_ignore_defaults => $selinux_ignore_defaults, |
|
70 |
selrange => $selrange, |
|
71 |
selrole => $selrole, |
|
72 |
seltype => $seltype, |
|
73 |
seluser => $seluser, |
|
74 |
} |
|
75 |
|
|
76 |
$template_real = $template ? { |
|
77 |
undef => 'inline', |
|
78 |
default => $template, |
|
79 |
} |
|
80 |
|
|
81 |
$template_body_real = $template_body ? { |
|
82 |
undef => template_body($template_real), |
|
83 |
default => $template_body, |
|
84 |
} |
|
85 |
|
|
86 |
datacat_collector { $title: |
|
87 |
template => $template_real, |
|
88 |
template_body => $template_body_real, |
|
89 |
target_resource => File[$title], # when we evaluate we modify the private data of this resource |
|
90 |
target_field => 'content', |
|
91 |
collects => $collects, |
|
92 |
before => File[$title], # we want to evaluate before that resource so it can do the work |
|
93 |
} |
|
94 |
} |
|
95 |
} |