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

Why Puppet can require each package just once?

· 52CE 我爱测

When defining dependencies in a class each Package can be globally defined just once. I have hierarchy of configuration and some packages should be installed on all machines (that goes to default configuration) but other should b…

问题原文

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

When defining dependencies in a class each Package can be globally defined just once. I have hierarchy of configuration and some packages should be installed on all machines (that goes to default configuration) but other should be installed only on some category of machines. How I am supposed to check whether that package is already on a machine when Puppet threat is as a duplicate declaration?

  Duplicate declaration: Package[wget] is already declared 

should I use a function like this?

  if defined( Package[$package] ) {
    debug("$package already installed")
  } else {
    package { $package: ensure => $ensure }
  }

I would expect from configuration tool to deal whith this issue by default... am I missing something?

已采纳解答

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

You can use the ensure_resource() from stdlib module:

$packages = $::osfamily ? {
    'Debian' => [ 'fcgiwrap', ],
    'RedHat' => [ 'spawn-fcgi', 'git' ],
}
ensure_resource('package', $packages, {'ensure' => 'present'})

So, say, if git is installed by some other class already, that would be skipped. You should not care of defining a package only once throughout the puppet configuration.

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

资料来源与适用范围

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

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

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