Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
386 views
in Technique[技术] by (71.8m points)

puppet - Check file existence on target machine using Bolt

Looking in the Bolt documentation, I didn't find how to check the existence of a file on the remote machine using Puppet plans.

Using get_resources could be used but the problem is that it requires the Puppet agent to be installed on the remote machine which is something I want to avoid for the moment.

Another way to do is to use a shell script with run_command and it will probably be my way to handle this.

Any other idea ?

question from:https://stackoverflow.com/questions/66046351/check-file-existence-on-target-machine-using-bolt

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...