]> git.madduck.net Git - puppet/sudo.git/blob - manifests/init.pp

madduck's git repository

Every one of the projects in this repository is available at the canonical URL git://git.madduck.net/madduck/pub/<projectpath> — see each project's metadata for the exact URL.

All patches and comments are welcome. Please squash your changes to logical commits before using git-format-patch and git-send-email to patches@git.madduck.net. If you'd read over the Git project's submission guidelines and adhered to them, I'd be especially grateful.

SSH access, as well as push access can be individually arranged.

If you use my repositories frequently, consider adding the following snippet to ~/.gitconfig and using the third clone URL listed for each project:

[url "git://git.madduck.net/madduck/"]
  insteadOf = madduck:

split into files
[puppet/sudo.git] / manifests / init.pp
1 class sudo (
2     Optional[String[1]] $sudogroup = undef,
3 ) {
4     $include_directory = '/etc/sudoers.d'
5     $file_defaults = {
6         owner        => "root",
7         group        => "root",
8         mode         => "0440",
9         validate_cmd => "sh -c 'if ! visudo --check --file=%; then cat %; exit 1; fi'",
10     }
11     $default_target = '00-defaults'
12
13     include sudo::install
14     include sudo::files
15     include sudo::defaults
16
17     define option (
18         Optional[String[1]] $parameter = undef,
19         Variant[String[1],Array[String[1]],Integer,Boolean] $value = true,
20         Enum['generic','host','user','cmnd','runas'] $context = 'generic',
21         Optional[Variant[Array[String[1]],String[1]]] $list = undef,
22         String[1] $target = $sudo::default_target,
23         Integer $order = 10,
24         Optional[String[1]] $comment = undef,
25         Boolean $newline_before = true,
26     ) {
27         $param = $parameter ? { undef => $name, default => $parameter }
28         $_list = type($list) ? { list => $list, default => [$list] }
29         sudo::internals::add_sudoers_fragment { "${name}":
30             target  => $target,
31             content => template("sudo/option_line.erb"),
32             order   => $order,
33             comment => $comment,
34         }
35     }
36
37     define alias (
38         Enum['host','user','cmnd','runas'] $type,
39         Optional[Variant[Array[String[1]],String[1]]] $list = undef,
40         String[1] $target = $sudo::default_target,
41         Integer $order = 10,
42         Optional[String[1]] $comment = undef,
43         Boolean $newline_before = true,
44     ) {
45         if $name !~ /^[[:upper:]][[:upper:]_[:digit:]]*$/ {
46             fail("sudoers alias definition '$name' can only contain uppercase letter, numbers, and the underscore")
47         }
48         $_list = type($list) ? { list => $list, default => [$list] }
49         sudo::internals::add_sudoers_fragment { "${name}":
50             target  => $target,
51             content => template("sudo/alias_line.erb"),
52             order   => $order,
53             comment => $comment,
54         }
55     }
56
57     define rule (
58         Variant[Array[String[1]],String[1]] $who,
59         Variant[Array[String[1]],String[1]] $where = 'ALL',
60         Optional[Variant[Array[String[1]],String[1]]] $as_whom = 'ALL',
61         Optional[Variant[Array[String[1]],String[1]]] $as_group = 'ALL',
62         Variant[Array[String[1]],String[1]] $what,
63         String[1] $target = $sudo::default_target,
64         Integer $order = 10,
65         Optional[String[1]] $comment = undef,
66         Boolean $newline_before = true,
67     )
68     {
69         $_comment = $comment ? { undef => $name, default => $comment }
70         sudo::internals::add_sudoers_fragment { "${name}":
71             target  => $target,
72             content => template("sudo/rule_line.erb"),
73             order   => $order,
74             comment => $comment,
75         }
76     }
77 }