]> git.donarmstrong.com Git - dsa-puppet.git/blob - modules/site/manifests/aptrepo.pp
d5bae7812dd5b736b5640a8f0190a3f6cf1cb3d6
[dsa-puppet.git] / modules / site / manifests / aptrepo.pp
1 define site::aptrepo ($key = undef, $keyid = undef, $template = undef, $config = undef, $ensure = present) {
2
3         case $ensure {
4                 present: {
5                         if $key {
6                                 exec { "apt-key-update-${name}":
7                                         command     => "apt-key add /etc/apt/trusted-keys.d/${name}.asc",
8                                         refreshonly => true,
9                                 }
10
11                                 file { "/etc/apt/trusted-keys.d/${name}.asc":
12                                         source => $key,
13                                         mode   => '0664',
14                                         notify => Exec["apt-key-update-${name}"]
15                                 }
16                         }
17                 }
18                 absent:  {
19                         if ($keyid) and ($key) {
20                                 file { "/etc/apt/trusted-keys.d/${name}.asc":
21                                         ensure => absent,
22                                         notify => Exec["apt-key-del-${keyid}"]
23                                 }
24                                 exec { "apt-key-del-${keyid}":
25                                         command     => "apt-key del ${keyid}",
26                                         refreshonly => true,
27                                 }
28                         } elsif $key {
29                                 file { "/etc/apt/trusted-keys.d/${name}.asc":
30                                         ensure => absent,
31                                 }
32                         } elsif $keyid {
33                                 exec { "apt-key-del-${keyid}":
34                                         command     => "apt-key del ${keyid}",
35                                 }
36                         }
37                 }
38                 default: { fail ( "Unknown ensure value: '$ensure'" ) }
39         }
40
41         if $ensure == present {
42                 if ! ($config or $template) {
43                         fail ( "No configuration found for ${name}" )
44                 }
45         }
46
47         if $template {
48                 file { "/etc/apt/sources.list.d/${name}.list":
49                         ensure  => $ensure,
50                         content => template($template),
51                         notify => Exec['apt-get update'],
52                 }
53         } else {
54                 file { "/etc/apt/sources.list.d/${name}.list":
55                         ensure => $ensure,
56                         source => $config,
57                         notify => Exec['apt-get update'],
58                 }
59         }
60 }