Merge pull request #889 from puppetlabs/pdksync_remove_support_ubuntu14
[puppet-modules/puppetlabs-apt.git] / manifests / backports.pp
1 # @summary Manages backports.
2 #
3 # @example Set up a backport for linuxmint qiana
4 #   apt::backports { 'qiana':
5 #     location => 'http://us.archive.ubuntu.com/ubuntu',
6 #     release  => 'trusty-backports',
7 #     repos    => 'main universe multiverse restricted',
8 #     key      => {
9 #       id     => '630239CC130E1A7FD81A27B140976EAF437D05B5',
10 #       server => 'hkps.pool.sks-keyservers.net',
11 #     },
12 #   }
13 #
14 # @param location
15 #   Specifies an Apt repository containing the backports to manage. Valid options: a string containing a URL. Default value for Debian and 
16 #   Ubuntu varies:
17 #
18 #   - Debian: 'http://deb.debian.org/debian'
19 #
20 #   - Ubuntu: 'http://archive.ubuntu.com/ubuntu'
21 #
22 # @param release
23 #   Specifies a distribution of the Apt repository containing the backports to manage. Used in populating the `source.list` configuration file. 
24 #   Default: on Debian and Ubuntu, '${lsbdistcodename}-backports'. We recommend keeping this default, except on other operating 
25 #   systems.
26 #
27 # @param repos
28 #   Specifies a component of the Apt repository containing the backports to manage. Used in populating the `source.list` configuration file. 
29 #   Default value for Debian and Ubuntu varies:
30 #   
31 #   - Debian: 'main contrib non-free'
32 #
33 #   - Ubuntu: 'main universe multiverse restricted'
34 #
35 # @param key
36 #   Specifies a key to authenticate the backports. Valid options: a string to be passed to the id parameter of the apt::key defined type, or a 
37 #   hash of parameter => value pairs to be passed to apt::key's id, server, content, source, and/or options parameters. Default value
38 #   for Debian and Ubuntu varies:
39 #
40 #   - Debian: 'A1BD8E9D78F7FE5C3E65D8AF8B48AD6246925553'
41 #
42 #   - Ubuntu: '630239CC130E1A7FD81A27B140976EAF437D05B5'
43 #
44 # @param pin
45 #   Specifies a pin priority for the backports. Valid options: a number or string to be passed to the `id` parameter of the `apt::pin` defined 
46 #   type, or a hash of `parameter => value` pairs to be passed to `apt::pin`'s corresponding parameters.
47 #
48 class apt::backports (
49   Optional[String] $location                    = undef,
50   Optional[String] $release                     = undef,
51   Optional[String] $repos                       = undef,
52   Optional[Variant[String, Hash]] $key          = undef,
53   Optional[Variant[Integer, String, Hash]] $pin = 200,
54 ){
55   if $location {
56     $_location = $location
57   }
58   if $release {
59     $_release = $release
60   }
61   if $repos {
62     $_repos = $repos
63   }
64   if $key {
65     $_key = $key
66   }
67   if (!($facts['lsbdistid'] == 'Debian' or $facts['lsbdistid'] == 'Ubuntu')) {
68     unless $location and $release and $repos and $key {
69       fail(translate('If not on Debian or Ubuntu, you must explicitly pass location, release, repos, and key'))
70     }
71   }
72   unless $location {
73     $_location = $::apt::backports['location']
74   }
75   unless $release {
76     $_release = "${facts['lsbdistcodename']}-backports"
77   }
78   unless $repos {
79     $_repos = $::apt::backports['repos']
80   }
81   unless $key {
82     $_key =  $::apt::backports['key']
83   }
84
85   if $pin =~ Hash {
86     $_pin = $pin
87   } elsif $pin =~ Numeric or $pin =~ String {
88     # apt::source defaults to pinning to origin, but we should pin to release
89     # for backports
90     $_pin = {
91       'priority' => $pin,
92       'release'  => $_release,
93     }
94   } else {
95     fail(translate('pin must be either a string, number or hash'))
96   }
97
98   apt::source { 'backports':
99     location => $_location,
100     release  => $_release,
101     repos    => $_repos,
102     key      => $_key,
103     pin      => $_pin,
104   }
105 }