puppet - 如何确保 puppet exec 在每个触发的事件上运行?
问题描述
我希望 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;
}
}
解决方案
使用 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
推荐阅读
- excel - Excel 中是否有类似 Application.Intersect(Target, Range) 的谷歌脚本方法?
- java - 多部分文件到 .zip
- css - bootstrap 4 中心标题和右对齐按钮都在一行中
- google-chrome-extension - 使用 Chrome 扩展获取 DOM 内容
- r - 通过在 R 中随时间增加计数来子集
- sql-server - 我们可以用相同的主键制作不同表链接的多个外键吗?
- c++ - 模板上的运算符重载
- ios - 无法使用 Codable 和 Alamofire 3.0 解析数据
- node.js - 在一个查询中计算具有多个条件的文档
- c++ - Compactify C++ 函数调用语法