We are currently using remote_file with source as an array. This allows us to check multiple servers for the file we want, in case the primary server is down.

We want to log which source remote_file ended up downloading the file from. I assume the log resource would be used, but I'm not sure how to find out which one of the provided sources were used by remote_file.

Super simplified example

urlArray = ['google.com','reddit.com','stackexchange.com']
remote_file 'foo' do
   source urlArray
   notifies :write, 'Downloaded from: #{sourceUsed}', :immediate
log 'Downloaded from: #{sourceUsed}' do
    action :nothing
  • Resources in chef doesn't return anything, the use case sounds weird and as such I highly doubt it would be included in core chef, best bet could be 'forking' the remote_file resource into a custom resource to add this log part inside the provider (logging in debug mode should give the information, but that means having the whole run in debug or a heavy tweak to change the log level around this resource)
    – Tensibai
    Aug 29 '17 at 21:00
  • For the sake of curiosity I'll have a look at the code...
    – Tensibai
    Aug 29 '17 at 21:01
  • 3
    For what it worth chef already log at warn level the failed sources and at info level the source before trying, so the one working is the next one in the array after the last failed from this code github.com/chef/chef/blob/…
    – Tensibai
    Aug 29 '17 at 21:11
  • Hmm, I've taken a look at the code that you linked. And it looks exactly like what I need. Thanks!
    – george
    Aug 30 '17 at 3:08
  • @george So this means that the question has been answered? Could you post an answer?
    – 030
    Dec 8 '17 at 11:00

Browse other questions tagged or ask your own question.