Body: <p>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.</p>
  
  <p>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.</p>
  
  <p>Super simplified example</p>
  
  <pre><code>urlArray = ['google.com','reddit.com','stackexchange.com']
  remote_file 'foo' do
     source urlArray
     notifies :write, 'Downloaded from: #{sourceUsed}', :immediate
  end
  log 'Downloaded from: #{sourceUsed}' do
      action :nothing
  end
  </code></pre>
  
Comments: CC BY-SA 3.0
Comments: 2017-08-29T21:00:39.613Z
Comments: 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)
Comments: Tensibai
Comments: CC BY-SA 3.0
Comments: 2017-08-29T21:01:19.787Z
Comments: For the sake of curiosity I'll have a look at the code...
Comments: Tensibai
Comments: CC BY-SA 3.0
Comments: 2017-08-29T21:11:11.317Z
Comments: 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 https://github.com/chef/chef/blob/0971e0a472f70318a41b75de308269999175d772/lib/chef/provider/remote_file/content.rb#L58
Comments: Tensibai
Comments: CC BY-SA 3.0
Comments: 2017-08-30T03:08:51.817Z
Comments: Hmm, I've taken a look at the code that you linked. And it looks exactly like what I need.
  Thanks!
Comments: george
Comments: CC BY-SA 3.0
Comments: 2017-12-08T11:00:55.460Z
Comments: @george So this means that the question has been answered? Could you post an answer?
Comments: 030
Tags: <chef>
Title: Logging the source of remote file when using array using Chef
UserDisplayName: george
ThreadText: # Logging the source of remote file when using array using Chef
  
  (Asked by: username_0 on 2017-08-29)
  
  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
  end
  log 'Downloaded from: #{sourceUsed}' do
      action :nothing
  end
  
  ```
  
  **Tags:** chef
  
  > **Comments:**
  > **username_1**: 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)  
  > **username_1**: For the sake of curiosity I'll have a look at the code...  
  > **username_1**: 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 https://github.com/chef/chef/blob/0971e0a472f70318a41b75de308269999175d772/lib/chef/provider/remote_file/content.rb#L58  
  > **username_0**: Hmm, I've taken a look at the code that you linked. And it looks exactly like what I need. Thanks!  
  > **username_2**: @username_0 So this means that the question has been answered? Could you post an answer?  
  
  ---
  
  ## 0 answers
  
  