File: init.pp

package info (click to toggle)
puppet-module-richardc-datacat 0.6.2-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 208 kB
  • sloc: ruby: 417; sh: 10; makefile: 4
file content (95 lines) | stat: -rw-r--r-- 3,125 bytes parent folder | download | duplicates (3)
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# Definition: datacat
#
# This definition allows you to declare datacat managed files.
#
# Parameters:
# All parameters are as for the file type, with the addition of a $template
# parameter which is a path to a template to be used as the content of the
# file.
#
# Sample Usage:
#  datacat { '/etc/motd':
#    owner => 'root',
#    group => 'root,
#    template => 'motd/motd.erb',
#  }
#
define datacat(
  $ensure                  = 'file',
  $template                = undef,
  $template_body           = undef,
  $collects                = [],
  $backup                  = undef,
  $checksum                = undef,
  $force                   = undef,
  $group                   = undef,
  $owner                   = undef,
  $mode                    = undef,
  $path                    = $title,
  $replace                 = undef,
  $selinux_ignore_defaults = undef,
  $selrange                = undef,
  $selrole                 = undef,
  $seltype                 = undef,
  $seluser                 = undef,
  $show_diff               = 'UNSET'
) {
  if $show_diff != 'UNSET' {
    if versioncmp($settings::puppetversion, '3.2.0') >= 0 {
      File { show_diff => $show_diff }
    } else {
      warning('show_diff not supported in puppet prior to 3.2, ignoring')
    }
  }

  # we could validate ensure by simply passing it to file, but unfortunately
  # someone could try to be smart and pass 'directory', so we only allow a limited range
  if $ensure != 'absent' and $ensure != 'present' and $ensure != 'file' {
    fail("Datacat[${title}] invalid value for ensure")
  }

  if $ensure == 'absent' {
    file { $title:
      ensure                  => $ensure,
      path                    => $path,
      backup                  => $backup,
      force                   => $force,
    }
  } else {
    file { $title:
      path                    => $path,
      backup                  => $backup,
      checksum                => $checksum,
      content                 => "To be replaced by datacat_collector[${title}]\n",
      force                   => $force,
      group                   => $group,
      mode                    => $mode,
      owner                   => $owner,
      replace                 => $replace,
      selinux_ignore_defaults => $selinux_ignore_defaults,
      selrange                => $selrange,
      selrole                 => $selrole,
      seltype                 => $seltype,
      seluser                 => $seluser,
    }

    $template_real = $template ? {
      undef   => 'inline',
      default => $template,
    }

    $template_body_real = $template_body ? {
      undef   => template_body($template_real),
      default => $template_body,
    }

    datacat_collector { $title:
      template        => $template_real,
      template_body   => $template_body_real,
      target_resource => File[$title], # when we evaluate we modify the private data of this resource
      target_field    => 'content',
      collects        => $collects,
      before          => File[$title], # we want to evaluate before that resource so it can do the work
    }
  }
}