Answers: <p>What I do for this case is using node attributes hash for a key value mapping as follow :</p>
  
  <p>In <code>attributes/default.rb</code></p>
  
  <pre><code>default['namespace']['files']['file1']='http://server1/path/source_fileX'
  default['namespace']['files']['file2']='http://server2/path/source_fileY'
  </code></pre>
  
  <p>Or with hash notation :</p>
  
  <pre><code>default['namespace']['files']={'file1' =&gt; 'http://server1/path/source_fileX',
  'file2'=&gt;'http://server2/path/source_fileY'}
  </code></pre>
  
  <p>Then in recipe:</p>
  
  <pre><code>node['namespace']['files'].each do |filename,src|
    remote_file "/path/destinaton/#{filename}" do
      source src
      mode '0644'
      action :create
    end
  end
  </code></pre>
  
  <p>This way you can map a file with its source taking advantage that node attributes are a hash structure. </p>
  
  <p>If course you can set the full path instead of just the file name and avoid the string interpolation in the recipe remote_file.</p>
  
  <p>(Typed on phone, please forgive typos)</p>
  
Answers: CC BY-SA 3.0
Answers: 2017-04-27T20:22:27.010Z
Answers: 2017-04-27T20:22:27.010Z
Answers: Tensibai
Answers: <p>what about something like that:</p>
  
  <pre><code>%w{
          mysql-community-common-5.7.16-1.el7.x86_64.rpm
          mysql-community-libs-5.7.16-1.el7.x86_64.rpm
          mysql-community-client-5.7.16-1.el7.x86_64.rpm
          mysql-community-server-5.7.16-1.el7.x86_64.rpm
  }.each do |pkg|
          remote_file "/tmp/#{pkg}" do
            source "https://s3.amazonaws.com/tmp/mysql/#{pkg}"
          end
  
         rpm_package pkg do
          source "/tmp/#{pkg}"
          action :install
        end
  end
  </code></pre>
  
  <p>another way:</p>
  
  <pre><code>urllist = {
    { 'url': 'http://some.url1/', 'path': '/some/path1/', 'filename': 'some.file' },
    { 'url': 'https://some.url2/', 'path': '/some/path2/', 'filename': 'another.file'}
  }
  
  urllist.each do |urlinfo|
    remote_file "#{urlinfo['path']}/#{urlinfo['filename']}" do
      source "#{urlinfo['url']}/#{urlinfo['filename']}"
      owner 'someowner'
      group 'somegroup'
      mode 0755
    end
  end
  </code></pre>
  
Answers: CC BY-SA 3.0
Answers: 2017-04-27T20:03:57.307Z
Answers: looks great @Berlin. is there ant way I can setup path to install them. I would like to install some plugins for Jenkins in a specified path like eg: '/opt/XXX/plugins/'. I want to download those plugins into plugins folder but some times it says plugins exists but its a folder
Answers: pandey
Answers: CC BY-SA 3.0
Answers: 2017-04-27T20:12:50.677Z
Answers: @Berlin it worked for me. Is there any way that I can write attribute for those rpm that you mentioned
Answers: pandey
Answers: CC BY-SA 3.0
Answers: 2017-04-27T20:26:30.793Z
Answers: `mysql-community-common-5.7.16-1.el7.x86_64.rpm
          mysql-community-libs-5.7.16-1.el7.x86_64.rpm
          mysql-community-client-5.7.16-1.el7.x86_64.rpm
          mysql-community-server-5.7.16-1.el7.x86_64.rpm
  `  How can I write this thing as attribute
Answers: pandey
Answers: CC BY-SA 3.0
Answers: 2017-04-27T20:29:47.013Z
Answers: see below @Tensibai answer `attributes/default.rb`, is it what you looking for ?
Answers: Berlin
Answers: CC BY-SA 3.0
Answers: 2017-04-27T20:33:53.403Z
Answers: @berlin sorry for the edit,  seems my phone disagree with me on spaces and it is not better :/ I let you fix it,  that's a valid options for multiples files from same source
Answers: Tensibai
Answers: CC BY-SA 3.0
Answers: 2017-04-27T20:39:37.310Z
Answers: @Tensibai no worries, it is fine.
Answers: Berlin
Answers: CC BY-SA 3.0
Answers: 2017-04-27T20:43:01.130Z
Answers: @berlin for information you can paste indented code,  select it an press the code button (the {} ) or ctrl+k to indent a block with 4 spaces and keep original format
Answers: Tensibai
Answers: CC BY-SA 3.0
Answers: 2017-04-27T20:53:19.850Z
Answers: when I do as @Tensibai way for attributes I am getting error as undefined method `each' for
Answers: pandey
Answers: CC BY-SA 3.0
Answers: 2017-04-27T20:58:52.943Z
Answers: @pandey edit your question to show what you did,  guessing won't help to help you)
Answers: Tensibai
Answers: CC BY-SA 3.0
Answers: 2017-04-27T21:13:31.083Z
Answers: @pandey or maybe better,  ask a new one as a follow up from this one with your actual problem to not invalidate actual answers
Answers: Tensibai
Answers: CC BY-SA 3.0
Answers: 2017-04-27T21:25:42.583Z
Answers: I solved it @Tensibai its a spacing problem. its my bad....thanks for your help. I am thankful to both of you and Berlin
Answers: pandey
Answers: CC BY-SA 3.0
Answers: 2017-04-27T21:30:41.927Z
Answers: @pandey you're welcome :) I hope I won't sound selfish but think about upvoting answers you find useful and as you already did accept the one you prefer
Answers: Tensibai
Answers: CC BY-SA 3.0
Answers: 2017-04-27T21:38:17.223Z
Answers: because he did not ask from the beginning on `attributes` :)
Answers: Berlin
Answers: CC BY-SA 3.0
Answers: 2017-04-27T19:53:09.713Z
Answers: 2017-04-27T21:04:02.517Z
Answers: 2017-04-27T21:04:02.517Z
Answers: Berlin
Body: <p>I am wondering if there is a resource to download multiple files from remote using chef resource. I want to use: </p>
  
  <pre><code>remote_file 'Download remote file' do
    path /opt/
    source http:///xxx
    mode '0644'
    action :create
  end
  </code></pre>
  
  <p>...for one file. What if I want to download multiple files in a same place with different urls? Or how can I modify this resource to make multiple downloads which have different URLs?</p>
  
  <p>This is how I added attributes in recipe: </p>
  
  <pre><code>node['file']['name'].each do |pkg|
      remote_file "path/plugins/#{pkg}" do
          source "node['file']['url']/#{pkg}"
          action :create
      end
  end
  </code></pre>
  
  <p>in attributes</p>
  
  <pre><code>default['file']['name'] = %w(
      xx-2.0.jar
      xx-2.jar
      xx.jar
      )
  </code></pre>
  
Comments: CC BY-SA 3.0
Comments: 2017-04-27T19:13:18.827Z
Comments: See the `remote_directory` resource,  documentation : https://docs.chef.io/resource_remote_directory.html
Comments: Tensibai
Comments: CC BY-SA 3.0
Comments: 2017-04-27T19:38:38.930Z
Comments: @Tensibai I couldn't see there anything with multiple URL's
Comments: pandey
Comments: CC BY-SA 3.0
Comments: 2017-04-27T19:52:29.403Z
Comments: Aww, sorry,  I did miss this point, a loop sounds the way to go,  you'll have to specify early h file BTW.  I'll try an answer, but there can be typo
Comments: Tensibai
Tags: <chef>
Title: Downloading multple files from remote using chef resource
UserDisplayName: pandey
ThreadText: # Downloading multple files from remote using chef resource
  
  (Asked by: username_0 on 2017-04-27)
  
  I am wondering if there is a resource to download multiple files from remote using chef resource. I want to use:
  
  ```
  remote_file 'Download remote file' do
    path /opt/
    source http:///xxx
    mode '0644'
    action :create
  end
  
  ```
  
  ...for one file. What if I want to download multiple files in a same place with different urls? Or how can I modify this resource to make multiple downloads which have different URLs?
  
  This is how I added attributes in recipe:
  
  ```
  node['file']['name'].each do |pkg|
      remote_file "path/plugins/#{pkg}" do
          source "node['file']['url']/#{pkg}"
          action :create
      end
  end
  
  ```
  
  in attributes
  
  ```
  default['file']['name'] = %w(
      xx-2.0.jar
      xx-2.jar
      xx.jar
      )
  
  ```
  
  **Tags:** chef
  
  > **Comments:**
  > **username_1**: See the `remote_directory` resource,  documentation : https://docs.chef.io/resource_remote_directory.html  
  > **username_0**: @username_1 I couldn't see there anything with multiple URL's  
  > **username_1**: Aww, sorry,  I did miss this point, a loop sounds the way to go,  you'll have to specify early h file BTW.  I'll try an answer, but there can be typo  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_2 on 2017-04-27. Score: 5 | Accepted answer
  
  what about something like that:
  
  ```
  %w{
          mysql-community-common-5.7.16-1.el7.x86_64.rpm
          mysql-community-libs-5.7.16-1.el7.x86_64.rpm
          mysql-community-client-5.7.16-1.el7.x86_64.rpm
          mysql-community-server-5.7.16-1.el7.x86_64.rpm
  }.each do |pkg|
          remote_file "/tmp/#{pkg}" do
            source "https://s3.amazonaws.com/tmp/mysql/#{pkg}"
          end
  
         rpm_package pkg do
          source "/tmp/#{pkg}"
          action :install
        end
  end
  
  ```
  
  another way:
  
  ```
  urllist = {
    { 'url': 'http://some.url1/', 'path': '/some/path1/', 'filename': 'some.file' },
    { 'url': 'https://some.url2/', 'path': '/some/path2/', 'filename': 'another.file'}
  }
  
  urllist.each do |urlinfo|
    remote_file "#{urlinfo['path']}/#{urlinfo['filename']}" do
      source "#{urlinfo['url']}/#{urlinfo['filename']}"
      owner 'someowner'
      group 'somegroup'
      mode 0755
    end
  end
  
  ```
  
  > **Comments:**
  > **username_0**: looks great @username_2. is there ant way I can setup path to install them. I would like to install some plugins for Jenkins in a specified path like eg: '/opt/XXX/plugins/'. I want to download those plugins into plugins folder but some times it says plugins exists but its a folder  
  > **username_0**: @username_2 it worked for me. Is there any way that I can write attribute for those rpm that you mentioned  
  > **username_0**: `mysql-community-common-5.7.16-1.el7.x86_64.rpm         mysql-community-libs-5.7.16-1.el7.x86_64.rpm         mysql-community-client-5.7.16-1.el7.x86_64.rpm         mysql-community-server-5.7.16-1.el7.x86_64.rpm `  How can I write this thing as attribute  
  > **username_2**: see below @username_1 answer `attributes/default.rb`, is it what you looking for ?  
  > **username_1**: @username_2 sorry for the edit,  seems my phone disagree with me on spaces and it is not better :/ I let you fix it,  that's a valid options for multiples files from same source  
  > **username_2**: @username_1 no worries, it is fine.  
  > **username_1**: @username_2 for information you can paste indented code,  select it an press the code button (the {} ) or ctrl+k to indent a block with 4 spaces and keep original format  
  > **username_0**: when I do as @username_1 way for attributes I am getting error as undefined method `each' for  
  > **username_1**: @username_0 edit your question to show what you did,  guessing won't help to help you)  
  > **username_1**: @username_0 or maybe better,  ask a new one as a follow up from this one with your actual problem to not invalidate actual answers  
  > **username_0**: I solved it @username_1 its a spacing problem. its my bad....thanks for your help. I am thankful to both of you and username_2  
  > **username_1**: @username_0 you're welcome :) I hope I won't sound selfish but think about upvoting answers you find useful and as you already did accept the one you prefer  
  > **username_2**: because he did not ask from the beginning on `attributes` :)  
  
  ---
  
  ### Answer by username_1 on 2017-04-27. Score: 2
  
  What I do for this case is using node attributes hash for a key value mapping as follow :
  
  In `attributes/default.rb`
  
  ```
  default['namespace']['files']['file1']='http://server1/path/source_fileX'
  default['namespace']['files']['file2']='http://server2/path/source_fileY'
  
  ```
  
  Or with hash notation :
  
  ```
  default['namespace']['files']={'file1' => 'http://server1/path/source_fileX',
  'file2'=>'http://server2/path/source_fileY'}
  
  ```
  
  Then in recipe:
  
  ```
  node['namespace']['files'].each do |filename,src|
    remote_file "/path/destinaton/#{filename}" do
      source src
      mode '0644'
      action :create
    end
  end
  
  ```
  
  This way you can map a file with its source taking advantage that node attributes are a hash structure.
  
  If course you can set the full path instead of just the file name and avoid the string interpolation in the recipe remote\_file.
  
  (Typed on phone, please forgive typos)
  
  
  ---
  
  