1a9ea1bcaefb4c629209cc25543b9e63308d6757
[puppet-modules/puppetlabs-apt.git] / manifests / backports.pp
1 # @summary Manages backports.
2 #
3 # @example Set up a backport source for Linux Mint qiana
4 #   class { 'apt::backports':
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 => 'keyserver.ubuntu.com',
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, `${fact('os.distro.codename')}-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   Variant[Integer, String, Hash] $pin           = 200,
57   Variant[Hash] $include                        = {},
58 ) {
59   include apt
60
61   if $location {
62     $_location = $location
63   }
64   if $release {
65     $_release = $release
66   }
67   if $repos {
68     $_repos = $repos
69   }
70   if $key {
71     $_key = $key
72   }
73   if (!($facts['os']['name'] == 'Debian' or $facts['os']['name'] == 'Ubuntu')) {
74     unless $location and $release and $repos and $key {
75       fail('If not on Debian or Ubuntu, you must explicitly pass location, release, repos, and key')
76     }
77   }
78   unless $location {
79     $_location = $::apt::backports['location']
80   }
81   unless $release {
82     if fact('os.distro.codename') {
83       $_release = "${fact('os.distro.codename')}-backports"
84     } else {
85       fail('os.distro.codename fact not available: release parameter required')
86     }
87   }
88   unless $repos {
89     $_repos = $::apt::backports['repos']
90   }
91   unless $key {
92     $_key =  $::apt::backports['key']
93   }
94
95   if $pin =~ Hash {
96     $_pin = $pin
97   } elsif $pin =~ Numeric or $pin =~ String {
98     # apt::source defaults to pinning to origin, but we should pin to release
99     # for backports
100     $_pin = {
101       'priority' => $pin,
102       'release'  => $_release,
103     }
104   } else {
105     fail('pin must be either a string, number or hash')
106   }
107
108   apt::source { 'backports':
109     location => $_location,
110     release  => $_release,
111     repos    => $_repos,
112     include  => $include,
113     key      => $_key,
114     pin      => $_pin,
115   }
116 }