(maint) - add back gems removed by pdk update
[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 # @param include
49 #   Specifies whether to include 'deb' or 'src', or both.
50 #
51 class apt::backports (
52   Optional[String] $location                    = undef,
53   Optional[String] $release                     = undef,
54   Optional[String] $repos                       = undef,
55   Optional[Variant[String, Hash]] $key          = undef,
56   Optional[Variant[Integer, String, Hash]] $pin = 200,
57   Optional[Variant[Hash]] $include              = {},
58 ){
59
60   include apt
61
62   if $location {
63     $_location = $location
64   }
65   if $release {
66     $_release = $release
67   }
68   if $repos {
69     $_repos = $repos
70   }
71   if $key {
72     $_key = $key
73   }
74   if (!($facts['lsbdistid'] == 'Debian' or $facts['lsbdistid'] == 'Ubuntu')) {
75     unless $location and $release and $repos and $key {
76       fail(translate('If not on Debian or Ubuntu, you must explicitly pass location, release, repos, and key'))
77     }
78   }
79   unless $location {
80     $_location = $::apt::backports['location']
81   }
82   unless $release {
83     $_release = "${facts['lsbdistcodename']}-backports"
84   }
85   unless $repos {
86     $_repos = $::apt::backports['repos']
87   }
88   unless $key {
89     $_key =  $::apt::backports['key']
90   }
91
92   if $pin =~ Hash {
93     $_pin = $pin
94   } elsif $pin =~ Numeric or $pin =~ String {
95     # apt::source defaults to pinning to origin, but we should pin to release
96     # for backports
97     $_pin = {
98       'priority' => $pin,
99       'release'  => $_release,
100     }
101   } else {
102     fail(translate('pin must be either a string, number or hash'))
103   }
104
105   apt::source { 'backports':
106     location => $_location,
107     release  => $_release,
108     repos    => $_repos,
109     include  => $include,
110     key      => $_key,
111     pin      => $_pin,
112   }
113 }