0ca52123190d9a06157331e7f38a11c907779415
[puppet-modules/puppetlabs-apt.git] / manifests / source.pp
1 # source.pp
2 # add an apt source
3 define apt::source(
4   $comment           = $name,
5   $ensure            = present,
6   $location          = '',
7   $release           = $::lsbdistcodename,
8   $repos             = 'main',
9   $include_src       = false,
10   $include_deb       = true,
11   $key               = undef,
12   $key_server        = 'keyserver.ubuntu.com',
13   $key_content       = undef,
14   $key_source        = undef,
15   $pin               = false,
16   $architecture      = undef,
17   $trusted_source    = false,
18 ) {
19   validate_string($architecture, $comment, $location, $release, $repos, $key_server)
20   validate_bool($trusted_source, $include_src, $include_deb)
21
22   if ! $release {
23     fail('lsbdistcodename fact not available: release parameter required')
24   }
25
26   file { "${name}.list":
27     ensure  => $ensure,
28     path    => "${::apt::sources_list_d}/${name}.list",
29     owner   => root,
30     group   => root,
31     mode    => '0644',
32     content => template('apt/_header.erb', 'apt/source.list.erb'),
33     notify  => Exec['apt_update'],
34   }
35
36
37   if ($pin != false) {
38     # Get the host portion out of the url so we can pin to origin
39     $url_split = split($location, '/')
40     $host      = $url_split[2]
41
42     apt::pin { $name:
43       ensure   => $ensure,
44       priority => $pin,
45       before   => File["${name}.list"],
46       origin   => $host,
47     }
48   }
49
50   # We do not want to remove keys when the source is absent.
51   if $key and ($ensure == 'present') {
52     apt::key { "Add key: ${key} from Apt::Source ${title}":
53       ensure      => present,
54       key         => $key,
55       key_server  => $key_server,
56       key_content => $key_content,
57       key_source  => $key_source,
58       before      => File["${name}.list"],
59     }
60   }
61
62   # Need anchor to provide containment for dependencies.
63   anchor { "apt::source::${name}":
64     require => Class['apt::update'],
65   }
66 }