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