Chef在Windows上下载并安装Oracle Java

时间:2017-05-25 06:47:26

标签: java chef silent-installer

我想在Windows 7上安装带有Chef 13的Java。

从文件安装很简单,但我也想从Oracle档案中下载它。问题是,Oracle需要特殊的cookie - oraclelicense=accept-securebackup-cookie

我已经尝试了java食谱,因为看起来人们没有遇到任何问题。 Hovewer,跑完厨师后我得到错误:

Recipe: java::notify
  * log[jdk-version-changed] action nothing (skipped due to action :nothing)
Recipe: java::windows
  * ruby_block[Enable Accessing cookies] action run
    - execute the ruby block Enable Accessing cookies
  * remote_file[C:/Users/User\.chef\local-mode-cache\cache/jdk-7u79-windows-i586.exe] action create[2017-05-25T08:30:21+02:00] WARN: remote_file[C:/Users/User\.chef\local-mode-cache\cache/jdk-7u79-windows-i586.exe] cannot be downloaded from http://download.oracle.com/otn/java/jdk/7u79-b15/jdk-7u79-windows-i586.exe: 401 "Authorization Required"
[2017-05-25T08:30:21+02:00] WARN: remote_file[C:/Users/User\.chef\local-mode-cache\cache/jdk-7u79-windows-i586.exe] cannot be downloaded from http://download.oracle.com/otn/java/jdk/7u79-b15/jdk-7u79-windows-i586.exe: 401 "Authorization Required"


  ================================================================================
  Error executing action `create` on resource 'remote_file[C:/Users/User\.chef\local-mode-cache\cache/jdk-7u79-windows-i586.exe]'
  ================================================================================

  Net::HTTPServerException
  ------------------------
  401 "Authorization Required"

  Resource Declaration:
  ---------------------
  # In C:/Users/User/.chef/local-mode-cache/cache/cookbooks/java/recipes/windows.rb

   62:   remote_file cache_file_path do
   63:     checksum pkg_checksum if pkg_checksum
   64:     source node['java']['windows']['url']
   65:     backup false
   66:     action :create
   67:   end
   68: end

  Compiled Resource:
  ------------------
  # Declared in C:/Users/User/.chef/local-mode-cache/cache/cookbooks/java/recipes/windows.rb:62:in `from_file'

  remote_file("C:/Users/User\.chef\local-mode-cache\cache/jdk-7u79-windows-i586.exe") do
    provider Chef::Provider::RemoteFile
    action [:create]
    default_guard_interpreter :default
    source ["http://download.oracle.com/otn/java/jdk/7u79-b15/jdk-7u79-windows-i586.exe"]
    use_etag true
    use_last_modified true
    declared_type :remote_file
    cookbook_name "java"
    recipe_name "windows"
    path "C:/Users/User\\.chef\\local-mode-cache\\cache/jdk-7u79-windows-i586.exe"
    checksum nil
    rights nil
    deny_rights nil
    verifications []
  end

  System Info:
  ------------
  chef_version=13.0.118
  platform=windows
  platform_version=6.1.7600
  ruby=ruby 2.4.1p111 (2017-03-22 revision 58053) [i386-mingw32]
  program_name=C:/opscode/chef/bin/chef-client
  executable=C:/opscode/chef/bin/chef-client

正如您在上面的日志中所看到的,我已将['java']['oracle']['accept_oracle_download_terms']设置为true(execute the ruby block Enable Accessing cookies)。

由于这本食谱对我来说不起作用,我已经尝试过自己的java食谱:

windows_package package_name do
       source                 source
       action                 :install
       installer_type         :custom
       remote_file_attributes ({
         :headers => {"Cookie" => "oraclelicense=accept-securebackup-cookie"}
      })
      options                 opts
end

......它仍然会出现同样的错误。

在Oracle网站上有任何改变,下载JDK不再起作用吗?或者我必须设置防火墙或什么?

1 个答案:

答案 0 :(得分:0)

Oracle不时会引入这样的变化,不幸的是,这很常见。由于从常规用户的角度来看无法做任何事情,因此最好的解决方案是自己托管软件包,并修改节点属性以指向该源。这就是我的工作,属性看起来像这样(对于linux和samba共享):

"java": {
  "install_flavor": "oracle",
  "jdk_version": "8",
  "jdk" : {
    "8" : {
      "x86_64" : {
        "url" : "file:///path/to/jdk-8u131-linux-x64.tar.gz",
        "checksum": "the file's checksum"
      }
    }
  }
}

这样,像Oracle那样的更改不再是问题。