06165b6c2210433522beb0804378861630bfd902
[puppet-modules/puppetlabs-apt.git] / manifests / backports.pp
1 class apt::backports (
2   Optional[Variant[String, Stdlib::Compat::String]] $location = undef,
3   Optional[Variant[String, Stdlib::Compat::String]] $release = undef,
4   Optional[Variant[String, Stdlib::Compat::String]] $repos = undef,
5   Optional[Variant[String, Stdlib::Compat::String, Hash, Stdlib::Compat::Hash]] $key = undef,
6   Optional[Variant[Integer, Stdlib::Compat::Integer, String, Stdlib::Compat::String, Hash, Stdlib::Compat::Hash]] $pin  = 200,
7 ){
8   if $location {
9     validate_legacy(String, 'validate_string', $location)
10     $_location = $location
11   }
12   if $release {
13     validate_legacy(String, 'validate_string', $release)
14     $_release = $release
15   }
16   if $repos {
17     validate_legacy(String, 'validate_string', $repos)
18     $_repos = $repos
19   }
20   if $key {
21     unless is_hash($key) {
22       validate_legacy(String, 'validate_string', $key)
23     }
24     $_key = $key
25   }
26   if ($facts['lsbdistid'] == 'Debian' or $facts['lsbdistid'] == 'Ubuntu') {
27     unless $location {
28       $_location = $::apt::backports['location']
29     }
30     unless $release {
31       $_release = "${facts['lsbdistcodename']}-backports"
32     }
33     unless $repos {
34       $_repos = $::apt::backports['repos']
35     }
36     unless $key {
37       $_key =  $::apt::backports['key']
38     }
39   } else {
40     unless $location and $release and $repos and $key {
41       fail('If not on Debian or Ubuntu, you must explicitly pass location, release, repos, and key')
42     }
43   }
44
45   if is_hash($pin) {
46     $_pin = $pin
47   } elsif is_numeric($pin) or is_string($pin) {
48     # apt::source defaults to pinning to origin, but we should pin to release
49     # for backports
50     $_pin = {
51       'priority' => $pin,
52       'release'  => $_release,
53     }
54   } else {
55     fail('pin must be either a string, number or hash')
56   }
57
58   apt::source { 'backports':
59     location => $_location,
60     release  => $_release,
61     repos    => $_repos,
62     key      => $_key,
63     pin      => $_pin,
64   }
65 }