Puppet 木偶';s Exec[]是否仅忽略?

Puppet 木偶';s Exec[]是否仅忽略?,puppet,Puppet,我在玩偶的Exec类型中遇到了一个非常奇怪的行为 我在一个类中有两个类似的Exec[],都带有onlyif参数,如下所示。问题是总是执行Exec['apt-update'](即每次Puppet的代理应用其清单时),即使onlyif条件为false,这与Exec['install-newrelic-apt-key']工作正常不同 注意:myExec[]的路径($path)在此类之外配置,所有命令在命令行中都按预期工作 *上面的代码是公共域,您可以随意使用。我不相信您的命令只会执行您期望的shell

我在玩偶的Exec类型中遇到了一个非常奇怪的行为

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

注意:my
Exec[]
的路径($path)在此类之外配置,所有命令在命令行中都按预期工作


*上面的代码是公共域,您可以随意使用。

我不相信您的
命令只会执行您期望的shell插值。我会尝试切换到
,除非这样的
语句:

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代理进程之后,它才按照预期开始工作


对我来说,这听起来像是傀儡中的一个bug。

我将尝试使用“除非”,但为什么Exec[“install newrelic apt key”]可以工作?好吧,使用除非工作正常!非常感谢@gabrtv!但仍然不清楚为什么onlyif不起作用……哇,实际上它不起作用!puppet继续记录
Jun 8 13:09:41代理puppet代理[31841]:(/Stage[main]/Newrelic::Server/Exec[apt-update]/returns)成功执行
,只为
Exec['apt-update']
我发现了这个秘密!事实上,清单是正确的,但在我重新启动puppet代理进程后,它才按照预期开始工作。奇怪,不是吗?听起来像个虫子。@semente很高兴你发现了!很难说确切的原因是什么。。虽然听起来像是真正的傀儡密码是对的。如果你能复制它,你应该在
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"],
  }