Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 13 additions & 34 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ This module provides helpful definitions for dealing with *yum*.
Module has been tested on:

* Puppet 4.10.9 and newer
* CentOS 7,8
* CentOS 8,9
* Amazon Linux 2017
* RHEL 7
* RHEL 8,9
* Fedora 35,36

For the official list of all tested distributions, please take a look at the metadata.json.
Expand Down Expand Up @@ -345,53 +345,32 @@ yum::plugin { 'versionlock':
ensure => present,
}
```
The module must be included to purge any unmanaged versionlock files on the system.

### Lock a package with the *versionlock* plugin
The `versionlock` type changed between CentOS 7 and CentOS 8.

#### CentOS 7 and older
Locks explicitly specified packages from updates. Package name must be precisely
specified in format *`EPOCH:NAME-VERSION-RELEASE.ARCH`*. Wild card in package
name is allowed provided it does not span a field seperator.
Specify the version and some of the release, epoch or arch values as parameters.

```puppet
yum::versionlock { '0:bash-4.1.2-9.el6_2.*':
ensure => present,
yum::versionlock{'bash':
ensure => present,
version => '4.1.2',
release => '9.el8.2.*',
epoch => 0,
arch => 'x86_64',
}
```

Use the following command to retrieve a properly-formated string:

```sh
PACKAGE_NAME='bash'
rpm -q "$PACKAGE_NAME" --qf '%|EPOCH?{%{EPOCH}}:{0}|:%{NAME}-%{VERSION}-%{RELEASE}.%{ARCH}\n'
```

To run a `yum clean all` after the versionlock file is updated.
To run a `dnf clean all` after the versionlock file is updated.

```puppet
class{'yum::plugin::versionlock':
clean => true,
}
yum::versionlock { '0:bash-4.1.2-9.el6_2.*':
ensure => present,
}
```

Note the CentOS 8 mechansim can be used if the parameter
`version` is also set to anything other than the default `undef`. This allows
common code to be used on CentOS 7 and 8 if the new style is used.

#### CentOS 8 and newer
Specify some of the version, release, epoch and arch values as parameters.

```puppet
yum::versionlock{'bash':
yum::versionlock { 'bash':
ensure => present,
version => '4.1.2',
release => '9.el8.2.*',
epoch => 0,
arch => 'x86_64',
release => '9.el9_2',
}
```

Expand Down
56 changes: 17 additions & 39 deletions REFERENCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,8 @@ Data type: `String`

filepath for the versionlock.list, default based on your system.

Default value: `'/etc/dnf/plugins/versionlock.list'`

### <a name="yum--settings"></a>`yum::settings`

Simple settings to use
Expand Down Expand Up @@ -747,32 +749,12 @@ The command to run

Locks package from updates.

* **Note** The resource title must use the format
By default on CentOS 7 the following format is used.
"%{EPOCH}:%{NAME}-%{VERSION}-%{RELEASE}.%{ARCH}". This can be retrieved via
the command `rpm -q --qf '%{EPOCH}:%{NAME}-%{VERSION}-%{RELEASE}.%{ARCH}'.
If "%{EPOCH}" returns as '(none)', it should be set to '0'. Wildcards may
be used within token slots, but must not cover seperators, e.g.,
'0:b*sh-4.1.2-9.*' covers Bash version 4.1.2, revision 9 on all
architectures.
By default on CentOS 8 and newer the resource title to just set the
package name.
If a version is set on CentOS 7 then it behaves like CentOS 8

* **See also**
* http://man7.org/linux/man-pages/man1/yum-versionlock.1.html
* https://dnf-plugins-core.readthedocs.io/en/latest/versionlock.html

#### Examples

##### Sample usage on CentOS 7

```puppet
yum::versionlock { '0:bash-4.1.2-9.el7.*':
ensure => present,
}
```

##### Sample usage on CentOS 8
##### Sample usage

```puppet
yum::versionlock { 'bash':
Expand All @@ -784,18 +766,6 @@ yum::versionlock { 'bash':
}
```

##### Sample usage on CentOS 7 with new style version, release, epoch, name parameters.

```puppet
yum::versionlock { 'bash':
ensure => present,
version => '3.1.2',
release => '9.el7',
epoch => 0,
arch => 'noarch',
}
```

#### Parameters

The following parameters are available in the `yum::versionlock` defined type:
Expand All @@ -805,6 +775,7 @@ The following parameters are available in the `yum::versionlock` defined type:
* [`release`](#-yum--versionlock--release)
* [`arch`](#-yum--versionlock--arch)
* [`epoch`](#-yum--versionlock--epoch)
* [`package`](#-yum--versionlock--package)

##### <a name="-yum--versionlock--ensure"></a>`ensure`

Expand All @@ -818,35 +789,42 @@ Default value: `'present'`

Data type: `Optional[Yum::RpmVersion]`

Version of the package if CentOS 8 mechanism is used. This must be set for dnf based systems (e.g CentOS 8).
If version is set then the name var is assumed to a package name and not the full versionlock string.
Version of the package

Default value: `undef`

##### <a name="-yum--versionlock--release"></a>`release`

Data type: `Yum::RpmRelease`

Release of the package if CentOS 8 mechanism is used.
Release of the package

Default value: `'*'`

##### <a name="-yum--versionlock--arch"></a>`arch`

Data type: `Variant[Yum::RpmArch, Enum['*']]`

Arch of the package if CentOS 8 mechanism is used.
Arch of the package

Default value: `'*'`

##### <a name="-yum--versionlock--epoch"></a>`epoch`

Data type: `Variant[Integer[0], Pattern[/^[1-9]\d*$/]]`

Epoch of the package if CentOS 8 mechanism is used.
Epoch of the package

Default value: `0`

##### <a name="-yum--versionlock--package"></a>`package`

Data type: `Yum::RpmNameGlob`

The package name or package glob

Default value: `$title`

## Resource types

### <a name="dnf_module_stream"></a>`dnf_module_stream`
Expand Down
1 change: 0 additions & 1 deletion data/common.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,4 @@ lookup_options:
merge: 'unique'

# Default is currently yum path
yum::plugin::versionlock::path: /etc/yum/pluginconf.d/versionlock.list
yum::settings::mainconf: /etc/yum.conf
1 change: 0 additions & 1 deletion data/package_provider/dnf.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
---
yum::plugin::versionlock::path: /etc/dnf/plugins/versionlock.list
yum::settings::mainconf: /etc/dnf/dnf.conf
14 changes: 4 additions & 10 deletions manifests/plugin/versionlock.pp
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,13 @@
# }
#
class yum::plugin::versionlock (
String $path,
Enum['present', 'absent'] $ensure = 'present',
Boolean $clean = false,
Enum['present', 'absent'] $ensure = 'present',
String $path = '/etc/dnf/plugins/versionlock.list',
Boolean $clean = false,
) {
$pkg_prefix = $facts['package_provider'] ? {
'dnf' => 'python3-dnf-plugin',
'yum' => 'yum-plugin',
default => '',
}

yum::plugin { 'versionlock':
ensure => $ensure,
pkg_prefix => $pkg_prefix,
pkg_prefix => 'python3-dnf-plugin',
}

if $ensure == 'present' {
Expand Down
74 changes: 14 additions & 60 deletions manifests/versionlock.pp
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
# @summary Locks package from updates.
#
# @example Sample usage on CentOS 7
# yum::versionlock { '0:bash-4.1.2-9.el7.*':
# ensure => present,
# }
#
# @example Sample usage on CentOS 8
# @example Sample usage
# yum::versionlock { 'bash':
# ensure => present,
# version => '4.1.2',
Expand All @@ -14,81 +9,40 @@
# arch => 'noarch',
# }
#
# @param ensure Specifies if versionlock should be `present`, `absent` or `exclude`.
#
# @example Sample usage on CentOS 7 with new style version, release, epoch, name parameters.
# yum::versionlock { 'bash':
# ensure => present,
# version => '3.1.2',
# release => '9.el7',
# epoch => 0,
# arch => 'noarch',
# }
#
# @param ensure
# Specifies if versionlock should be `present`, `absent` or `exclude`.
# @param version Version of the package
#
# @param version
# Version of the package if CentOS 8 mechanism is used. This must be set for dnf based systems (e.g CentOS 8).
# If version is set then the name var is assumed to a package name and not the full versionlock string.
# @param release Release of the package
#
# @param release
# Release of the package if CentOS 8 mechanism is used.
# @param arch Arch of the package
#
# @param arch
# Arch of the package if CentOS 8 mechanism is used.
# @param epoch Epoch of the package
#
# @param epoch
# Epoch of the package if CentOS 8 mechanism is used.
# @param package The package name or package glob
#
# @note The resource title must use the format
# By default on CentOS 7 the following format is used.
# "%{EPOCH}:%{NAME}-%{VERSION}-%{RELEASE}.%{ARCH}". This can be retrieved via
# the command `rpm -q --qf '%{EPOCH}:%{NAME}-%{VERSION}-%{RELEASE}.%{ARCH}'.
# If "%{EPOCH}" returns as '(none)', it should be set to '0'. Wildcards may
# be used within token slots, but must not cover seperators, e.g.,
# '0:b*sh-4.1.2-9.*' covers Bash version 4.1.2, revision 9 on all
# architectures.
# By default on CentOS 8 and newer the resource title to just set the
# package name.
# If a version is set on CentOS 7 then it behaves like CentOS 8
# @see https://dnf-plugins-core.readthedocs.io/en/latest/versionlock.html
#
# @see http://man7.org/linux/man-pages/man1/yum-versionlock.1.html
define yum::versionlock (
Enum['present', 'absent', 'exclude'] $ensure = 'present',
Optional[Yum::RpmVersion] $version = undef,
Yum::RpmRelease $release = '*',
Variant[Integer[0], Pattern[/^[1-9]\d*$/]] $epoch = 0,
Variant[Yum::RpmArch, Enum['*']] $arch = '*',
Yum::RpmNameGlob $package = $title,
) {
if $ensure in ['present', 'exclude'] and ! $version {
fail('The version parameter must be set when ensure is present or exclude')
}

require yum::plugin::versionlock

$line_prefix = $ensure ? {
'exclude' => '!',
default => '',
}

if $facts['package_provider'] == 'yum' and $version =~ Undef {
assert_type(Yum::VersionlockString, $name) |$_expected, $actual | {
# lint:ignore:140chars
fail("Package name must be formatted as %{EPOCH}:%{NAME}-%{VERSION}-%{RELEASE}.%{ARCH}, not \'${actual}\'. See Yum::Versionlock documentation for details.")
# lint:endignore
}

$_versionlock = "${line_prefix}${name}"
} else {
assert_type(Yum::RpmNameGlob, $name) |$_expected, $actual | {
fail("Package name must be formatted as Yum::RpmName, not \'${actual}\'. See Yum::Rpmname documentation for details.")
}

assert_type(Yum::RpmVersion, $version) |$_expected, $actual | {
fail("Version must be formatted as Yum::RpmVersion, not \'${actual}\'. See Yum::RpmVersion documentation for details.")
}

$_versionlock = $facts['package_provider'] ? {
'yum' => "${line_prefix}${epoch}:${name}-${version}-${release}.${arch}",
default => "${line_prefix}${name}-${epoch}:${version}-${release}.${arch}",
}
}
$_versionlock = "${line_prefix}${name}-${epoch}:${version}-${release}.${arch}"

unless $ensure == 'absent' {
concat::fragment { "yum-versionlock-${name}":
Expand Down
Loading
Loading