Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I have a use case where most of my remote_file resources and yum resources download files directly from an internal server. However, there is a need to download one or two files with remote_file that is outside our firewall and which must go through a HTTP proxy. If I set the http_proxy setting in /etc/chef/client.rb, it adversely affects the recipe's ability to download yum and other files from internal resources. Is there a way to have a remote_file resource download a remote URL through a proxy without setting the http_proxy value in /etc/chef/client.rb?

In my sample code, below, I'm downloading a redmine bundle from rubyforge.org, which requires my servers to go through a corporate proxy. I came up with a ruby_block before and after the remote_file resource that sets the http_proxy and "unsets" it. I'm looking for a cleaner way to do this.

ruby_block "setenv-http_proxy" do
    block do
        Chef::Config.http_proxy = node['redmine']['http_proxy']
        ENV['http_proxy'] = node['redmine']['http_proxy']
        ENV['HTTP_PROXY'] = node['redmine']['http_proxy']
    action node['redmine']['rubyforge_use_proxy'] ? :create : :nothing
    notifies :create_if_missing, "remote_file[redmine-bundle.zip]", :immediately

remote_file "redmine-bundle.zip" do
    path "#{Dir.tmpdir}/redmine-#{attrs['version']}-bundle.zip"
    source attrs['download_url']
    mode "0644"
    action :create_if_missing
    notifies :decompress, "zipp[redmine-bundle.zip]", :immediately
    notifies :create, "ruby_block[unsetenv-http_proxy]", :immediately

ruby_block "unsetenv-http_proxy" do
    block do
        Chef::Config.http_proxy = nil
        ENV['http_proxy'] = nil
        ENV['HTTP_PROXY'] = nil
    action node['redmine']['rubyforge_use_proxy'] ? :create : :nothing
share|improve this question
add comment

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.