Merge branch '1.4.x' into 14x-merge
[puppet-modules/puppetlabs-apt.git] / manifests / hold.pp
1 # == Define apt::hold
2 #
3 # This defined type allows you to hold a package based on the version you
4 # require. It's implemented by dropping an apt preferences file pinning the
5 # package to the version you require.
6 #
7 # === Parameters
8 #
9 # [*version*]
10 #   The version at which you wish to pin a package.
11 #
12 #   This can either be the full version, such as 4:2.11.8.1-5, or
13 #   a partial version, such as 4:2.11.*
14 #
15 # [*package*]
16 #   _default_: +$title+, the title/name of the resource.
17 #
18 #   Name of the package that apt is to hold.
19 #
20 # [*priority*]
21 #   _default_: +1001+
22 #
23 #   The default priority of 1001 causes this preference to always win. By
24 #   setting the priority to a number greater than 1000 apt will always install
25 #   this version even if it means downgrading the currently installed version.
26 define apt::hold(
27   $version,
28   $ensure   = 'present',
29   $package  = $title,
30   $priority = 1001,
31 ){
32
33   validate_string($title)
34   validate_re($ensure, ['^present|absent',])
35   validate_string($package)
36   validate_string($version)
37
38   if ! is_integer($priority) {
39     fail('$priority must be an integer')
40   }
41
42   if $ensure == 'present' {
43     ::apt::pin { "hold ${package} at ${version}":
44       packages => $package,
45       version  => $version,
46       priority => $priority,
47     }
48   } else {
49     ::apt::pin { "hold ${package} at ${version}":
50       ensure => 'absent',
51     }
52   }
53
54 }