如何确保puppet exec在触发的每个事件上运行?

问题描述 投票:0回答:1

我希望puppet exec在文件的第一次部署和文件的每次进一步更改时运行。为此,我在puppet中创建了以下代码。

Exec不会在第一次文件部署时运行。我假设这是因为刷新。有谁知道代码中需要更改什么?

define dev_tools::javacert(
  $keystore="/etc/alternatives/java_sdk/jre/lib/security/cacerts",
  $storepass='xxx',
  $alias = $name,
  $filecertpath = "/var/lib/certs/${name}.crt",

){
  file{
    $filecertpath:
      source => "puppet:///modules/${module_name}/sonarqube/${::env}/${::server_location}/${filecertpath}",
      mode   => '0644',
      notify => Exec["deploy_javacert_${name}"];
  }
  exec {
    "deploy_javacert_${name}":
       path => "/usr/bin",
       command => "keytool -importcert -keystore ${keystore} -alias $alias -file $filecertpath -storepass ${storepass} -noprompt  2>/dev/null",
       provider => shell,
       refreshonly => true;
  }

}
puppet
1个回答
3
投票

使用refreshonly看起来是正确的。我无法重现这一点。使用此代码的简化版本:

尝试创建一个MCVE

# test.pp

file { 'foo': 
  path   => '/tmp/foo',
  source => '/tmp/source',
  notify => Exec['bar'],
}
exec { 'bar':
  path        => '/bin',
  command     => 'echo "baz qux"',
  refreshonly => true,
  logoutput   => true,
}

建立:

▶ touch /tmp/source 

初次运行:

▶ puppet apply test.pp
...
Notice: /Stage[main]/Main/File[foo]/content: content changed '{md5}0a227d644d5435d49addae1da06e909c' to '{md5}d41d8cd98f00b204e9800998ecf8427e'
Notice: /Stage[main]/Main/Exec[bar]/returns: baz qux
Notice: /Stage[main]/Main/Exec[bar]: Triggered 'refresh' from 1 event

后续运行:

▶ puppet apply test.pp
...
Notice: Compiled catalog for 192-168-1-2.tpgi.com.au in environment production in 0.08 seconds
Notice: Applied catalog in 0.03 seconds

新内容:

▶ echo foobar > /tmp/source
▶ puppet apply test.pp
...
Notice: /Stage[main]/Main/File[foo]/content: content changed '{md5}d41d8cd98f00b204e9800998ecf8427e' to '{md5}14758f1afd44c09b7992073ccf00b43d'
Notice: /Stage[main]/Main/Exec[bar]/returns: baz qux
© www.soinside.com 2019 - 2024. All rights reserved.