查看 Bolt 文档,我没有找到如何使用 Puppet 计划检查远程机器上是否存在文件。
可以使用get_resources,但问题是它需要在远程机器上安装 Puppet 代理,这是我暂时要避免的。
另一种方法是使用带有run_command的 shell 脚本,这可能是我处理这个问题的方法。
还有其他想法吗?
查看 Bolt 文档,我没有找到如何使用 Puppet 计划检查远程机器上是否存在文件。
可以使用get_resources,但问题是它需要在远程机器上安装 Puppet 代理,这是我暂时要避免的。
另一种方法是使用带有run_command的 shell 脚本,这可能是我处理这个问题的方法。
还有其他想法吗?
Bolt 的开发人员在这里,很高兴看到您在这里提出问题!实际上,我认为对于这个用例来说,在所有其他条件相同的情况下,run_command
它很可能比 更有效。get_resources
不确定您使用的是 Windows、*nix 还是两者,但假设 *nix 我认为您会想要类似的东西:
plan myplan(
TargetSpec $targets
) {
# test -f will return 0 if the file exists, 1 if it does not
$result_set = run_command("test -f /path/to/file", $targets, '_catch_errors' => true)
# Maybe you want to write the file if it doesn't exist:
upload_file('./myfile', '/path/to/file', $result_set.error_set.targets)
# This will be the list of targets the file does exist on:
run_task('mytask', $result_set.ok_set.targets)
}
没有比这更好或更“本机”的方法来检查远程系统上的文件是否存在。计划功能仅适用于本地机器,file::exist
因为它在 Bolt 中使用与我们用于查找模块、Bolt 配置等相同的文件查找器。但是该文件查找器在远程系统上不可用。