大网数据广告活动
服务器运维问答

Puppet Package class can't detect installed package when multiple versions are present

· 52CE 我爱测

I am trying to install the kernel-devel package matching the running kernel version. My guess was: package { 'kernel-devel': ensure => "${facts['kernelrelease']}", } but it doesn't work if more than one kernel-devel package are a…

问题原文

原帖链接 · David · CC BY-SA 4.0

I am trying to install the kernel-devel package matching the running kernel version.
My guess was:

  package { 'kernel-devel':
    ensure => "${facts['kernelrelease']}",
  }

but it doesn't work if more than one kernel-devel package are already installed. This is the error I get:

Error: Could not update: Failed to update to version 3.10.0-957.21.3.el7.x86_64, got version 3.10.0-957.21.3.el7; 3.10.0-1062.4.3.el7; 3.10.0-1062.9.1.el7 instead

So the package is already installed, but the Package class raises an error because (apparently) it performs a string comparison instead of looking in the versions list.

What is the proper way to handle this?

已采纳解答

原帖链接 · Aaron Copley · CC BY-SA 4.0

Unless I am misunderstanding, you can solve this with the version in the resource title.

package { "kernel-devel-${facts['kernelrelease']}":
  ensure => present,
}

Or, if you have other resources which depend on 'kernel-devel' you can use the name attribute.

package { 'kernel-devel':
  name   => "kernel-devel-${facts['kernelrelease']}",
  ensure => present,
}

[root@aaron ~]# dnf list installed kernel-devel
Installed Packages
kernel-devel.x86_64                                                                5.3.11-200.fc30                                                                @updates
kernel-devel.x86_64                                                                5.3.14-200.fc30                                                                @updates
[root@aaron ~]# uname -a
Linux aaron 5.3.15-200.fc30.x86_64 #1 SMP Thu Dec 5 15:18:00 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux
[root@aaron ~]# puppet apply kernel-devel.pp 
Notice: Compiled catalog for aaron.tsp in environment production in 0.54 seconds
Notice: /Stage[main]/Main/Package[kernel-devel-5.3.15-200.fc30.x86_64]/ensure: created
Notice: Applied catalog in 62.18 seconds
[root@aaron ~]# dnf list installed kernel-devel
Installed Packages
kernel-devel.x86_64                                                                5.3.11-200.fc30                                                                @updates
kernel-devel.x86_64                                                                5.3.14-200.fc30                                                                @updates
kernel-devel.x86_64                                                                5.3.15-200.fc30                                                                @updates

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2019-12-16)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。