Question

According to this release: http://docs.opscode.com/release/11-6/release_notes.html#resource-remote-file-attributes

Remote_file provider have the attribute "headers".

I would like to use it like this:

remote_file "foo" do
   source "http://someurl"
   headers({"Cookies" => "Some cookie"})
end

However this is not working as supposed, I mean, headers is not being used i guess. It's that the right sintax?

Was it helpful?

Solution

It's not the solution.. but it's a workaround

# install wget
windows_package "wget" do
   source "http://downloads.sourceforge.net/gnuwin32/wget-1.11.4-1-setup.exe"
   action :install
end

# Java uninstall, download and install
windows_batch "jre-7 installation" do
  code <<-EOH
     WMIC product where "Name LIKE '%%Java 7%%'" call uninstall /nointeractive
     "C:/Program Files (x86)/GnuWin32/bin/wget.exe" -O C:/chef/cache/jre-7.exe --no-check-certificate  --no-cookies --header "Cookie: gpw_e24=http%3A%2F%2Fwww.oracle.com;" http://download.oracle.com/otn-pub/java/jdk/7u25-b17/jdk-7u25-windows-x64.exe
      C:/chef/cache/jre-7.exe /s
 EOH
end

OTHER TIPS

This works for me in Chef10 and Chef11. Actually this feature is not documented - at least, I had to dig into Chef source code to find out how to pass cookies. Remote file does not support this. But we can use some "hidden" Chef mechanism to setup cookies to every request to particular domain and port.

ruby_block "Prepare cookies for download from http://someurl" do
  block do
    Chef::REST::CookieJar.instance["someurl:80"] = "Some cookie"
  end
end

remote_file "foo" do
   source "http://someurl"
end

Where ["someurl:80"] should be the whole domain with port. For example,

Chef::REST::CookieJar.instance["download.oracle.com:80"] = Chef::REST::CookieJar.instance["edelivery.oracle.com:443"] = "oraclelicense=accept-securebackup-cookie"

this can be used to download java from oracle site without manually accepting the license agreement.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top