Developer on Bolt here, very excited to see your question asked here! I actually think run_command
would most likely be more efficient for this use case than get_resources
, all other things being equal. Not sure if you're on Windows, *nix, or both, but assuming *nix I think you'll want something like:
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)
}
There isn't any better or more "native" way to check for the file existence on remote systems than that. The file::exist
plan function is for the local machine only since it uses the same file-finder in Bolt that we use to find modules, Bolt configuration, etc. But that file-finder isn't available on the remote systems.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…