Skip to content

Commit ada3913

Browse files
committed
feat: added support for common::packages::manage to set the pin for a package and updated the doc for package::install func and other misc bug fixes
1 parent ec1085b commit ada3913

File tree

3 files changed

+59
-28
lines changed

3 files changed

+59
-28
lines changed

modules/enableit/common/manifests/package.pp

Lines changed: 45 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,58 @@
44
Hash[
55
String,
66
Struct[{
7-
ensure => Optional[Variant[Enum['latest', 'present', 'purge', 'absent', 'installed'], String]],
7+
ensure => Optional[Stdlib::Ensure::Package],
88
noop => Optional[Boolean],
9+
pin => Optional[String],
910
}]
10-
] $manage = {},
11+
] $manage = {},
1112
Array[String] $default_packages = [],
1213
Array[String] $removed_packages = [],
1314
Array[String] $required_packages = [],
1415
) {
15-
$manage.each | $package_name, $status | {
16-
package { $package_name :
16+
17+
# Manage package
18+
$manage.each | $package_name, $options | {
19+
20+
confine($options['pin'], $options['ensure'] in ['present', 'absent'] or $options['ensure'] =~ Boolean, 'Package pinning requires an explicit package version') #lint:ignore:140chars
21+
22+
stdlib::ensure_packages($package_name, {
1723
# make sure the default is installed, even if it should change
18-
ensure => pick($status['ensure'], installed),
19-
noop => $status['noop'],
24+
ensure => pick($options['ensure'], installed),
25+
noop => $options['noop'],
26+
})
27+
28+
if $options['pin'] {
29+
case $facts['package_provider'] {
30+
'apt': {
31+
apt::pin { "pin ${package_name}":
32+
version => $options['pin'],
33+
priority => 999,
34+
packages => $package_name,
35+
}
36+
}
37+
/^(yum|dnf)$/: {
38+
$release = split($options['pin'], '-')
39+
40+
yum::versionlock { $package_name:
41+
ensure => present,
42+
version => $release[0],
43+
# NOTE: some package has like el8_10 (8.10) and some just have el8, so * will help to catch those
44+
release => "${release[1]}.el${facts['os']['release']['major']}*",
45+
arch => $facts['os']['architecture'],
46+
}
47+
}
48+
'zypper': {
49+
$full_package_name = "${package_name}-${options['pin']}-*.sles${facts['os']['release']['major']}*.${facts['os']['architecture']}"
50+
51+
zypprepo::versionlock { $full_package_name:
52+
ensure => present,
53+
}
54+
}
55+
default: {
56+
info('Unsupported package provider, please raise issue on github')
57+
}
58+
}
2059
}
2160
}
2261

modules/enableit/package/functions/install.pp

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,26 @@
33
# Tries to look up package names in hiera. If not found, uses package name as-is.
44
#
55
# @example
6-
# package::install('emacs')
7-
# package::install('rsync', 'absent')
8-
# package::install('python-pymongo', {notify => Service['diamond']})
9-
# package::install('hp-health', 'present' , '9.4.0.1.7-5.')
10-
# package::install('diamond', {notify => Service['diamond']} , '4.0.471')
6+
# Install emacs (will be in installed state)
7+
# package::install('emacs')
118
#
12-
# @param package_names One or more package names
13-
# @param status Package status
9+
# Remove the rsync package
10+
# package::install('rsync', 'absent')
11+
#
12+
# Install hp-health with a specific version, and notify some service
13+
# package::install('hp-health', {notify => Service['some-servicd']}))
14+
#
15+
# Install diamond package with a specific version, but does not set a pin
16+
# package::install('diamond', '4.0.471')
17+
#
18+
# @param packages One or more package names
1419
# @param parameters Additional parameters. These are merged with `status`.
1520

1621
function package::install (
1722
Variant[String, Array[String]] $packages,
18-
Variant[Boolean, Enum['present', 'absent'], Hash[String, Any], String] $parameters = {},
19-
Boolean $pin = false,
23+
Variant[Stdlib::Ensure::Package, Hash[String, Any]] $parameters = {},
2024
) {
2125

22-
confine($pin, $::facts['os']['family'] != 'Debian', 'Package pinning only supported on Debian-based systems')
23-
confine($pin, $parameters in ['present', 'absent'] or $parameters =~ Boolean, 'Package pinning requires an explicit package version')
24-
2526
# Packages
2627
$_packages = case $packages {
2728
String: {
@@ -42,15 +43,6 @@ function package::install (
4243
}
4344
}
4445

45-
if $pin {
46-
$_name = join($_packages, ', ')
47-
apt::pin { $_name:
48-
packages => $_packages,
49-
version => $parameters,
50-
priority => 999,
51-
}
52-
}
53-
5446
# Install/Remove Package
5547
$install_packages = package::lookup($_packages)
5648

modules/enableit/profile/manifests/system/sudoers.pp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@
6767
require => File[$sudoers_d_dir],
6868
}
6969

70-
package::install('pam-ssh-agent-auth', $common::system::authentication::sudo::ssh_agent_auth)
70+
package::install('pam-ssh-agent-auth', ensure_present($common::system::authentication::sudo::ssh_agent_auth))
7171

7272
$sudoers.each |$name, $v| {
7373
profile::system::sudoers::conf { $name:

0 commit comments

Comments
 (0)