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

Puppet: How to honor install_options of package() if specific package is installed already

· 52CE 我爱测

If one thinks of a better title for this question: Please change it accordingly. Environment: Debian jessie 8.5 puppet master: 3.8.5 puppet agent: 3.7.2 apt: 1.0.9.8.3 Problem: A specific package is installed already on the node,…

问题原文

原帖链接 · gxx · CC BY-SA 3.0

If one thinks of a better title for this question: Please change it accordingly.

Environment:

  • Debian jessie 8.5
  • puppet master: 3.8.5
  • puppet agent: 3.7.2
  • apt: 1.0.9.8.3

Problem:

A specific package is installed already on the node, let's take needrestart for example:

# dpkg -l | grep needrestart
ii  needrestart                     1.2-8+deb8u1

Using the following code:

package{[
  'needrestart',
]:
  ensure          => installed, # latest won't work, either
  install_options => ['-t', 'jessie-backports']
}

I would expect that needrestart is reinstalled / upgraded to the version out of jessie-backports. However, this doesn't happen, there is no reinstall / upgrade happening. Inside the (debug) logs there's nothing worth to be shown regarding this.

Solution:

In case this is not intended: Anyone knows a clever way around this?

已采纳解答

原帖链接 · M. Glatki · CC BY-SA 3.0

Your problem is, that your install_options will only be used if the package resource is actually installing your packages. You have a few options:

  • Use ensure => latest and hope for a package update (or trigger one yourself) - probably not what you want.
  • Upgrading to Puppet 4.x. Since version 4, Puppet has reinstall_on_refresh, which allows a reinstall on a notify event, if the provider supports reinstallable. While this works on Debian, this option is probably not useable for you.
  • Trick Puppet into thinking the package is uninstalled - this would need a puppet patch on your local installation, not recommended.
  • Patch Puppet with reinstallation capabilities: In this bug report from a few years ago, Aggelos Economopoulos supplied a patch for some version of puppet, which looks rather simple. This should get you started. I do not recommend patching your puppet agent installations, though.
  • Reinstall it yourself: Probably the only option you have for now: Write something along these lines:

    exec { "apt-get reinstall $package $your_options":
        user   => 'root',
        onlyif => 'dpkg -s $package| grep 'Version $your_version'
    }
    

    Depending on the differences of the packages with and without options, this can be arbitrarily hard. If only a handful of packages are affected, it can be managable.

  • Write your own provider and add it to package, or establish something like package_reinstall: It is surprisingly easy, can be managed and versioned via a module, and works without a Puppet update. I suggest starting with provider/package/apt.rb. This might be your best option after all.

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

资料来源与适用范围

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

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

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