patternMinor
Downloading multple files from remote using chef resource
Viewed 0 times
chefresourcedownloadingmultplefilesusingremotefrom
Problem
I am wondering if there is a resource to download multiple files from remote using chef resource. I want to use:
...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:
in attributes
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
endin attributes
default['file']['name'] = %w(
xx-2.0.jar
xx-2.jar
xx.jar
)Solution
what about something like that:
another way:
%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
endanother 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
endCode Snippets
%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
endurllist = {
{ '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
endContext
StackExchange DevOps Q#1048, answer score: 5
Revisions (0)
No revisions yet.