gpt4 book ai didi

Puppet 的 Exec[] 忽略 onlyif?

转载 作者:行者123 更新时间:2023-12-04 18:32:12 24 4
gpt4 key购买 nike

我在使用 Puppet 的 Exec 类型时遇到了一个非常奇怪的行为。

我在一个类中有两个类似的 Exec[],都带有 onlyif 参数,如下所示。问题是 Exec['apt-update'] 始终执行(即每次 Puppet 的代理应用其 list 时),即使 onlyif 条件为假,与 Exec['install-newrelic-apt-key'] 工作正常。

注意:我的 Exec[] 的路径($PATH)是在这个类之外配置的,所有命令都按预期在命令行中运行

class newrelic::server($license_key) {
file { "/etc/apt/sources.list.d/newrelic.list":
ensure => present,
content => "deb http://apt.newrelic.com/debian/ newrelic non-free",
}

exec { "apt-update":
command => "aptitude update",
onlyif => "test 0 -eq $(dpkg -l | grep -c newrelic-sysmond)",
require => File['/etc/apt/sources.list.d/newrelic.list'],
}

exec { "install-newrelic-apt-key":
command => "apt-key adv --keyserver hkp://subkeys.pgp.net --recv-keys 548C16BF",
onlyif => "test 0 -eq $(apt-key list | grep -c 548C16BF)",
}

package { "newrelic-sysmond":
ensure => latest,
require => [
Exec["install-newrelic-apt-key"],
Exec["apt-update"],
],
}

file { "/etc/newrelic/nrsysmond.cfg":
ensure => present,
content => template("newrelic/nrsysmond.erb"),
owner => "root",
group => "newrelic",
mode => "0640",
notify => Service["newrelic-sysmond"],
}

service { "newrelic-sysmond":
ensure => running,
enable => true,
hasstatus => true,
require => Package["newrelic-sysmond"],
}
}

* 以上代码属于公开领域,请随意使用。

最佳答案

我不相信您的 onlyif 命令会经历您期望的 shell 插值。我会尝试切换到 unless 语句:

class newrelic::server($license_key) {
file { "/etc/apt/sources.list.d/newrelic.list":
ensure => present,
content => "deb http://apt.newrelic.com/debian/ newrelic non-free",
}

exec { "apt-update":
command => "aptitude update",
unless => "dpkg -l | grep -c newrelic-sysmond",
require => File['/etc/apt/sources.list.d/newrelic.list'],
}

exec { "install-newrelic-apt-key":
command => "apt-key adv --keyserver hkp://subkeys.pgp.net --recv-keys 548C16BF",
unless => "apt-key list | grep -c 548C16BF",
}

package { "newrelic-sysmond":
ensure => latest,
require => [
Exec["install-newrelic-apt-key"],
Exec["apt-update"],
],
}

file { "/etc/newrelic/nrsysmond.cfg":
ensure => present,
content => template("newrelic/nrsysmond.erb"),
owner => "root",
group => "newrelic",
mode => "0640",
notify => Service["newrelic-sysmond"],
}

关于Puppet 的 Exec[] 忽略 onlyif?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16989789/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com