voxpupuli / puppet-yum

Puppet module for Yum
https://forge.puppet.com/puppet/yum
MIT License
16 stars 99 forks source link

Failed to call refresh: '/usr/bin/package-cleanup --oldkernels --count=2 -y' returned 1 instead of one of [0] #295

Closed hboetes closed 1 year ago

hboetes commented 1 year ago

package-cleanup uses a wrong syntax, resulting in this error message

Failed to call refresh: '/usr/bin/package-cleanup --oldkernels --count=2 -y' returned 1 instead of one of [0]

From the cli it looks like this:

# cat /etc/redhat-release 
Rocky Linux release 8.7 (Green Obsidian)
# /usr/bin/package-cleanup --oldkernels --count=2 -y
package-cleanup has to be executed with one of the options: --dupes, --leaves, --orphans, --problems or --cleandupes
gindelmer commented 1 year ago

For dnf the syntax has to be changed from /usr/bin/package-cleanup --oldkernels --count=2 -y to /bin/dnf remove -y $(/bin/dnf repoquery --installonly --latest-limit=-2)

https://dnf.readthedocs.io/en/latest/cli_vs_yum.html#changes-in-dnf-plugins-compared-to-yum-utilities

traylenator commented 1 year ago

Unfortunately

/bin/dnf remove -y $(/bin/dnf repoquery --installonly --latest-limit=-1

fails for the case when the latest kernel is not running:

# rpm -q kernel && uname -r
kernel-5.14.0-162.23.1.el9_1.x86_64
kernel-5.14.0-284.11.1.el9_2.x86_64
5.14.0-162.23.1.el9_1.x86_64

results in

#  /bin/dnf remove -y $(/bin/dnf repoquery --installonly --latest-limit=-1)
Error: 
 Problem: The operation would result in removing the following protected packages: kernel-core
(try to add '--skip-broken' to skip uninstallable packages or '--nobest' to use not only best candidate packages)
traylenator commented 1 year ago
dnf remove $(/bin/dnf repoquery  --installonly --latest-limit=-1 | grep -v $(facter kernelrelease))

to exclude running kernel...

Though part of me thinks this is all a bit scary and better to just wait for the next kernel update - it has an option for that however.

hboetes commented 1 year ago

For efficiency’s sake, please consider using $(uname -r) instead.

% time facter kernelrelease
6.2.15-300.fc38.x86_64
facter kernelrelease  0.14s user 0.04s system 101% cpu 0.174 total
time uname -r                                                         
6.2.15-300.fc38.x86_64
uname -r  0.00s user 0.00s system 73% cpu 0.001 total