0

I am a little new to chef and have been thorugh the tutorials, but I am starting to think I am not the one at fault:

I am trying to install Java on CentOS 7.2. it fails to install (apparently) - But extracts the tarball in the correct location, but adds a wildly inaccurate (I think) symlink and doesn't set the mode correctly.

Here is my LWRP:

#
# Cookbook Name:: install_java
# Recipe:: default
#
# Copyright (c) 2016 The Authors, All Rights Reserved.

# Used to define which OS to install and thus, which installer to use
op_sys = node['os']

# Used to get the required java update from the environment file
java_ver_update = node['java_ver']

# Logic for each OS
if op_sys == 'linux'
# Java_ark, which is used to define the correct install attributes for each OS type (win/linux)
  java_ark "jdk" do
    url 'http://sv-dc01.sv.local/install_artifacts/java/oracle/JRE/jre-'+"#{java_ver_update}"+'-linux-x64.tar.gz'
    app_home '/applications/JAVA/SomePath'
    owner 'root'
    group 'wheel'
    app_home_mode 774
    bin_cmds ['java', 'javaws', 'jcontrol', 'jjs', 'keytool', 'orbd', 'pack200', 'policytool', 'rmid', 'rmiregistry', 'servertool', 'tnameserv', 'unpack200']
    action :install
  end
# Same again but the logic for winows install
elsif op_sys == 'windows'
  java_ark "jdk" do
    url 'http://sv-dc01.sv.local/install_artifacts/java/oracle/JRE/jre-'+"#{java_ver_update}"+'-windows-x64.tar.gz'
    action :install
  end
end

include_recipe 'java'

Now, I have also defined some of the defaults in the environment file

name 'env_workstation'
description "Environment Workstation Dubbo"
cookbook_versions({
    "ohai" => "> 0.0.1",
    "java" => "> 0.1.0",
    "install_java" => "> 0.0.1"
})

$environment = Hash.new{|h,k| h[k]=Hash.new(&h.default_proc) }
$override = Hash.new{|h,k| h[k]=Hash.new(&h.default_proc) }

$override['java']['jdk_version'] = '8'
$override['java']['install_flavor'] = 'oracle'
$override['java_ver'] = '8u77'


default_attributes(Chef::Mixin::DeepMerge.merge($_default_environment, $environment))
override_attributes($override)

But the run fails even though the tarball is extracted to the correct location, but I then also end up with a symlink in a weird location named after the final folder of my java_ark '/applications/JAVA' (so JAVA).

Here is the run failure:

    Starting Chef Client, version 12.16.42
    resolving cookbooks for run list: ["install_java"]
    Synchronizing Cookbooks:
      - install_java (0.1.0)
      - java (1.42.0)
      - windows (2.1.1)
      - ohai (4.2.2)
      - compat_resource (12.16.2)
      - homebrew (2.1.2)
      - build-essential (7.0.2)
      - seven_zip (2.0.2)
      - mingw (1.2.4)
      - ark (2.1.0)
    Installing Cookbook Gems:
    Compiling Cookbooks...
    Converging 7 resources
    Recipe: install_java::default
      * java_ark[jdk] action install
        - create dir /applications/JAVA and change owner to root:wheel
        * remote_file[/var/chef/cache/jre-8u77-linux-x64.tar.gz] action create_if_missing
          - create new file /var/chef/cache/jre-8u77-linux-x64.tar.gz
          - update content in file /var/chef/cache/jre-8u77-linux-x64.tar.gz from none to edd9db
          (file sizes exceed 10000000 bytes, diff output suppressed)
          - change mode from '' to '0755'
          - restore selinux security context
        - extract compressed data into Chef file cache path and
                            move extracted data to /applications/JAVA/jre1.8.0_77
        - Symlink /applications/JAVA/jre1.8.0_77 to /applications/JAVA/SomePath
    Recipe: java::notify
      * log[jdk-version-changed] action write

      * remote_file[/var/chef/cache/jre-8u77-linux-x64.tar.gz] action nothing (skipped due to action :nothing)
      * java_alternatives[set-java-alternatives] action set
        - Add alternative for java
        - Add alternative for javaws
        - Add alternative for jcontrol
        - Add alternative for jjs
        - Add alternative for keytool
        - Add alternative for orbd
        - Add alternative for pack200
        - Add alternative for policytool
        - Add alternative for rmid
        - Add alternative for rmiregistry
        - Add alternative for servertool
        - Add alternative for tnameserv
        - Add alternative for unpack200
      * log[jdk-version-changed] action nothing (skipped due to action :nothing)
    Recipe: java::set_java_home
      * ruby_block[set-env-java-home] action run
        - execute the ruby block set-env-java-home
      * directory[/etc/profile.d] action create (up to date)
      * template[/etc/profile.d/jdk.sh] action create
        - create new file /etc/profile.d/jdk.sh
        - update content in file /etc/profile.d/jdk.sh from none to 5b75c4
        --- /etc/profile.d/jdk.sh   2016-12-06 17:01:08.234396652 +1300
        +++ /etc/profile.d/.chef-jdk20161206-4077-1pw7fk4.sh        2016-12-06 17:01:08.234396652 +1300
        @@ -1 +1,2 @@
        +export JAVA_HOME=/usr/lib/jvm/java
        - change mode from '' to '0755'
        - restore selinux security context
    Recipe: java::oracle
      * yum_package[tar] action install (up to date)
      * java_ark[jdk] action install
        - create dir /usr/lib/jvm and change owner to root:wheel[2016-12-06T17:01:22+13:00] FATAL: You must set the attribute node['java']['oracle']['accept_oracle_download_terms'] to true if you want 
    to download directly from the oracle site!

        ================================================================================
        Error executing action `install` on resource 'java_ark[jdk]'
        ================================================================================

        SystemExit
        ----------
        exit

        Cookbook Trace:
        ---------------
        /var/chef/cache/cookbooks/java/providers/ark.rb:86:in `download_direct_from_oracle'
        /var/chef/cache/cookbooks/java/providers/ark.rb:125:in `block in class_from_file'

        Resource Declaration:
        ---------------------
        # In /var/chef/cache/cookbooks/java/recipes/oracle.rb

         59: java_ark 'jdk' do
         60:   url tarball_url
         61:   default node['java']['set_default']
         62:   checksum tarball_checksum
         63:   app_home java_home
         64:   bin_cmds bin_cmds
         65:   alternatives_priority node['java']['alternatives_priority']
         66:   retries node['java']['ark_retries']
         67:   retry_delay node['java']['ark_retry_delay']
         68:   connect_timeout node['java']['ark_timeout']
         69:   use_alt_suffix node['java']['use_alt_suffix']
         70:   reset_alternatives node['java']['reset_alternatives']
         71:   download_timeout node['java']['ark_download_timeout']
         72:   action :install
         73:   notifies :write, 'log[jdk-version-changed]', :immediately
         74: end
         75: 
         76: if node['java']['set_default'] && platform_family?('debian')
         77:   include_recipe 'java::default_java_symlink'
         78: end
         79: 

        Compiled Resource:
        ------------------
        # Declared in /var/chef/cache/cookbooks/java/recipes/oracle.rb:59:in `from_file'

        java_ark("jdk") do
          action [:install]
          supports {:report=>true, :exception=>true}
          retries 0
          retry_delay 2
          default_guard_interpreter :default
          declared_type :java_ark
          cookbook_name "java"
          recipe_name "oracle"
          url "http://download.oracle.com/otn-pub/java/jdk/8u101-b13/jdk-8u101-linux-x64.tar.gz"
          app_home "/usr/lib/jvm/java"
          owner "root"
          group "wheel"
          app_home_mode 774
          bin_cmds ["appletviewer", "apt", "ControlPanel", "extcheck", "idlj", "jar", "jarsigner", "java", "javac", "javadoc", "javafxpackager", "javah", "javap", "javaws", "jcmd", "jconsole", "jcontro
    l", "jdb", "jdeps", "jhat", "jinfo", "jjs", "jmap", "jmc", "jps", "jrunscript", "jsadebugd", "jstack", "jstat", "jstatd", "jvisualvm", "keytool", "native2ascii", "orbd", "pack200", "policytool", "r
    mic", "rmid", "rmiregistry", "schemagen", "serialver", "servertool", "tnameserv", "unpack200", "wsgen", "wsimport", "xjc"]
          default true
          checksum "467f323ba38df2b87311a7818bcbf60fe0feb2139c455dfa0e08ba7ed8581328"
          alternatives_priority 1062
          connect_timeout 600
          use_alt_suffix true
          reset_alternatives true
          download_timeout 600
        end

        Platform:
        ---------
        x86_64-linux


    Running handlers:
    [2016-12-06T17:01:22+13:00] ERROR: Running exception handlers
    Running handlers complete
    [2016-12-06T17:01:22+13:00] ERROR: Exception handlers complete
    Chef Client failed. 6 resources updated in 40 seconds
    [2016-12-06T17:01:23+13:00] FATAL: Stacktrace dumped to /var/chef/cache/chef-stacktrace.out
    [2016-12-06T17:01:23+13:00] FATAL: Please provide the contents of the stacktrace.out file if you file a bug report
    [2016-12-06T17:01:23+13:00] ERROR: java_ark[jdk] (java::oracle line 59) had an error: SystemExit: exit
    [2016-12-06T17:01:23+13:00] FATAL: Chef::Exceptions::ChildConvergeError: Chef run process exited unsuccessfully (exit code 1)

Here is the stack trace:

Generated at 2016-12-06 17:01:23 +1300
SystemExit: java_ark[jdk] (java::oracle line 59) had an error: SystemExit: exit
/opt/chef/embedded/lib/ruby/gems/2.3.0/gems/chef-12.16.42/lib/chef/application.rb:367:in `exit'
/opt/chef/embedded/lib/ruby/gems/2.3.0/gems/chef-12.16.42/lib/chef/application.rb:367:in `fatal!'
/var/chef/cache/cookbooks/java/providers/ark.rb:86:in `download_direct_from_oracle'
/var/chef/cache/cookbooks/java/providers/ark.rb:125:in `block in class_from_file'
/opt/chef/embedded/lib/ruby/gems/2.3.0/gems/chef-12.16.42/lib/chef/provider/lwrp_base.rb:86:in `instance_eval'
/opt/chef/embedded/lib/ruby/gems/2.3.0/gems/chef-12.16.42/lib/chef/provider/lwrp_base.rb:86:in `block in action'
/opt/chef/embedded/lib/ruby/gems/2.3.0/gems/chef-12.16.42/lib/chef/provider.rb:145:in `run_action'
/opt/chef/embedded/lib/ruby/gems/2.3.0/gems/chef-12.16.42/lib/chef/resource.rb:622:in `run_action'
/opt/chef/embedded/lib/ruby/gems/2.3.0/gems/chef-12.16.42/lib/chef/runner.rb:69:in `run_action'
/opt/chef/embedded/lib/ruby/gems/2.3.0/gems/chef-12.16.42/lib/chef/runner.rb:97:in `block (2 levels) in converge'
/opt/chef/embedded/lib/ruby/gems/2.3.0/gems/chef-12.16.42/lib/chef/runner.rb:97:in `each'
/opt/chef/embedded/lib/ruby/gems/2.3.0/gems/chef-12.16.42/lib/chef/runner.rb:97:in `block in converge'
/opt/chef/embedded/lib/ruby/gems/2.3.0/gems/chef-12.16.42/lib/chef/resource_collection/resource_list.rb:94:in `block in execute_each_resource'
/opt/chef/embedded/lib/ruby/gems/2.3.0/gems/chef-12.16.42/lib/chef/resource_collection/stepable_iterator.rb:114:in `call_iterator_block'
/opt/chef/embedded/lib/ruby/gems/2.3.0/gems/chef-12.16.42/lib/chef/resource_collection/stepable_iterator.rb:85:in `step'
/opt/chef/embedded/lib/ruby/gems/2.3.0/gems/chef-12.16.42/lib/chef/resource_collection/stepable_iterator.rb:103:in `iterate'
/opt/chef/embedded/lib/ruby/gems/2.3.0/gems/chef-12.16.42/lib/chef/resource_collection/stepable_iterator.rb:55:in `each_with_index'
/opt/chef/embedded/lib/ruby/gems/2.3.0/gems/chef-12.16.42/lib/chef/resource_collection/resource_list.rb:92:in `execute_each_resource'
/opt/chef/embedded/lib/ruby/gems/2.3.0/gems/chef-12.16.42/lib/chef/runner.rb:96:in `converge'
/opt/chef/embedded/lib/ruby/gems/2.3.0/gems/chef-12.16.42/lib/chef/client.rb:669:in `block in converge'
/opt/chef/embedded/lib/ruby/gems/2.3.0/gems/chef-12.16.42/lib/chef/client.rb:664:in `catch'
/opt/chef/embedded/lib/ruby/gems/2.3.0/gems/chef-12.16.42/lib/chef/client.rb:664:in `converge'
/opt/chef/embedded/lib/ruby/gems/2.3.0/gems/chef-12.16.42/lib/chef/client.rb:703:in `converge_and_save'
/opt/chef/embedded/lib/ruby/gems/2.3.0/gems/chef-12.16.42/lib/chef/client.rb:283:in `run'
/opt/chef/embedded/lib/ruby/gems/2.3.0/gems/chef-12.16.42/lib/chef/application.rb:294:in `block in fork_chef_client'
/opt/chef/embedded/lib/ruby/gems/2.3.0/gems/chef-12.16.42/lib/chef/application.rb:282:in `fork'
/opt/chef/embedded/lib/ruby/gems/2.3.0/gems/chef-12.16.42/lib/chef/application.rb:282:in `fork_chef_client'
/opt/chef/embedded/lib/ruby/gems/2.3.0/gems/chef-12.16.42/lib/chef/application.rb:247:in `block in run_chef_client'
/opt/chef/embedded/lib/ruby/gems/2.3.0/gems/chef-12.16.42/lib/chef/local_mode.rb:44:in `with_server_connectivity'
/opt/chef/embedded/lib/ruby/gems/2.3.0/gems/chef-12.16.42/lib/chef/application.rb:235:in `run_chef_client'
/opt/chef/embedded/lib/ruby/gems/2.3.0/gems/chef-12.16.42/lib/chef/application/client.rb:464:in `sleep_then_run_chef_client'
/opt/chef/embedded/lib/ruby/gems/2.3.0/gems/chef-12.16.42/lib/chef/application/client.rb:451:in `block in interval_run_chef_client'
/opt/chef/embedded/lib/ruby/gems/2.3.0/gems/chef-12.16.42/lib/chef/application/client.rb:450:in `loop'
/opt/chef/embedded/lib/ruby/gems/2.3.0/gems/chef-12.16.42/lib/chef/application/client.rb:450:in `interval_run_chef_client'
/opt/chef/embedded/lib/ruby/gems/2.3.0/gems/chef-12.16.42/lib/chef/application/client.rb:434:in `run_application'
/opt/chef/embedded/lib/ruby/gems/2.3.0/gems/chef-12.16.42/lib/chef/application.rb:59:in `run'
/opt/chef/embedded/lib/ruby/gems/2.3.0/gems/chef-12.16.42/bin/chef-client:26:in `<top (required)>'
/bin/chef-client:54:in `load'
/bin/chef-client:54:in `<main>'

>>>> Caused by SystemExit: exit
/opt/chef/embedded/lib/ruby/gems/2.3.0/gems/chef-12.16.42/lib/chef/application.rb:367:in `exit'
/opt/chef/embedded/lib/ruby/gems/2.3.0/gems/chef-12.16.42/lib/chef/application.rb:367:in `fatal!'
/var/chef/cache/cookbooks/java/providers/ark.rb:86:in `download_direct_from_oracle'
/var/chef/cache/cookbooks/java/providers/ark.rb:125:in `block in class_from_file'
/opt/chef/embedded/lib/ruby/gems/2.3.0/gems/chef-12.16.42/lib/chef/provider/lwrp_base.rb:86:in `instance_eval'
/opt/chef/embedded/lib/ruby/gems/2.3.0/gems/chef-12.16.42/lib/chef/provider/lwrp_base.rb:86:in `block in action'
/opt/chef/embedded/lib/ruby/gems/2.3.0/gems/chef-12.16.42/lib/chef/provider.rb:145:in `run_action'
/opt/chef/embedded/lib/ruby/gems/2.3.0/gems/chef-12.16.42/lib/chef/resource.rb:622:in `run_action'
/opt/chef/embedded/lib/ruby/gems/2.3.0/gems/chef-12.16.42/lib/chef/runner.rb:69:in `run_action'
/opt/chef/embedded/lib/ruby/gems/2.3.0/gems/chef-12.16.42/lib/chef/runner.rb:97:in `block (2 levels) in converge'
/opt/chef/embedded/lib/ruby/gems/2.3.0/gems/chef-12.16.42/lib/chef/runner.rb:97:in `each'
/opt/chef/embedded/lib/ruby/gems/2.3.0/gems/chef-12.16.42/lib/chef/runner.rb:97:in `block in converge'
/opt/chef/embedded/lib/ruby/gems/2.3.0/gems/chef-12.16.42/lib/chef/resource_collection/resource_list.rb:94:in `block in execute_each_resource'
/opt/chef/embedded/lib/ruby/gems/2.3.0/gems/chef-12.16.42/lib/chef/resource_collection/stepable_iterator.rb:114:in `call_iterator_block'
/opt/chef/embedded/lib/ruby/gems/2.3.0/gems/chef-12.16.42/lib/chef/resource_collection/stepable_iterator.rb:85:in `step'
/opt/chef/embedded/lib/ruby/gems/2.3.0/gems/chef-12.16.42/lib/chef/resource_collection/stepable_iterator.rb:103:in `iterate'
/opt/chef/embedded/lib/ruby/gems/2.3.0/gems/chef-12.16.42/lib/chef/resource_collection/stepable_iterator.rb:55:in `each_with_index'
/opt/chef/embedded/lib/ruby/gems/2.3.0/gems/chef-12.16.42/lib/chef/resource_collection/resource_list.rb:92:in `execute_each_resource'
/opt/chef/embedded/lib/ruby/gems/2.3.0/gems/chef-12.16.42/lib/chef/runner.rb:96:in `converge'
/opt/chef/embedded/lib/ruby/gems/2.3.0/gems/chef-12.16.42/lib/chef/client.rb:669:in `block in converge'
/opt/chef/embedded/lib/ruby/gems/2.3.0/gems/chef-12.16.42/lib/chef/client.rb:664:in `catch'
/opt/chef/embedded/lib/ruby/gems/2.3.0/gems/chef-12.16.42/lib/chef/client.rb:664:in `converge'
/opt/chef/embedded/lib/ruby/gems/2.3.0/gems/chef-12.16.42/lib/chef/client.rb:703:in `converge_and_save'
/opt/chef/embedded/lib/ruby/gems/2.3.0/gems/chef-12.16.42/lib/chef/client.rb:283:in `run'
/opt/chef/embedded/lib/ruby/gems/2.3.0/gems/chef-12.16.42/lib/chef/application.rb:294:in `block in fork_chef_client'
/opt/chef/embedded/lib/ruby/gems/2.3.0/gems/chef-12.16.42/lib/chef/application.rb:282:in `fork'
/opt/chef/embedded/lib/ruby/gems/2.3.0/gems/chef-12.16.42/lib/chef/application.rb:282:in `fork_chef_client'
/opt/chef/embedded/lib/ruby/gems/2.3.0/gems/chef-12.16.42/lib/chef/application.rb:247:in `block in run_chef_client'
/opt/chef/embedded/lib/ruby/gems/2.3.0/gems/chef-12.16.42/lib/chef/local_mode.rb:44:in `with_server_connectivity'
/opt/chef/embedded/lib/ruby/gems/2.3.0/gems/chef-12.16.42/lib/chef/application.rb:235:in `run_chef_client'
/opt/chef/embedded/lib/ruby/gems/2.3.0/gems/chef-12.16.42/lib/chef/application/client.rb:464:in `sleep_then_run_chef_client'
/opt/chef/embedded/lib/ruby/gems/2.3.0/gems/chef-12.16.42/lib/chef/application/client.rb:451:in `block in interval_run_chef_client'
/opt/chef/embedded/lib/ruby/gems/2.3.0/gems/chef-12.16.42/lib/chef/application/client.rb:450:in `loop'
/opt/chef/embedded/lib/ruby/gems/2.3.0/gems/chef-12.16.42/lib/chef/application/client.rb:450:in `interval_run_chef_client'
/opt/chef/embedded/lib/ruby/gems/2.3.0/gems/chef-12.16.42/lib/chef/application/client.rb:434:in `run_application'
/opt/chef/embedded/lib/ruby/gems/2.3.0/gems/chef-12.16.42/lib/chef/application.rb:59:in `run'
/opt/chef/embedded/lib/ruby/gems/2.3.0/gems/chef-12.16.42/bin/chef-client:26:in `<top (required)>'
/bin/chef-client:54:in `load'
/bin/chef-client:54:in `<main>'[sysadmin@node1 ~]$ 
  • Possible duplicate of [Can the java cookbook be used to install a local copy of oracle java?](http://stackoverflow.com/questions/28776899/can-the-java-cookbook-be-used-to-install-a-local-copy-of-oracle-java) – Mark O'Connor Dec 11 '16 at 10:37

1 Answers1

3

As your FATAL log message indicates

FATAL: You must set the attribute node['java']['oracle']['accept_oracle_download_terms'] to true if you want to download directly from the oracle site!

You must accept Oracle's Java SE Archive License. To actively indicate you do so add,

$override['java']['jdk_version'] = '8'
$override['java']['install_flavor'] = 'oracle'
$override['java_ver'] = '8u77'
$override['java']['oracle']['accept_oracle_download_terms'] = true

You might also consider updating to a more recent version of Java (like 8u111).

Elliott Frisch
  • 198,278
  • 20
  • 158
  • 249
  • 1
    Dollar signs before `override`? – StephenKing Dec 06 '16 at 05:08
  • That is in my environment file to create an array of override settings and as such means that the way it is written is similar to how I would write them within the 'role' file. it works :D – Sean Vucich Dec 06 '16 at 20:17
  • Thank you - Now the install is working - But the only issue is that Java is put within "/applications/JAVA/jre_8u77" folder (Which is a folder down from the 'app_home' as per the recipe file, where is should be ''/applications/JAVA/SomePath") and creates a symlink to the JRE folder at the same level. What I actually want is Java deployed to the '/applications/JAVA/SomePath' without the symlink. What am I missing there? – Sean Vucich Dec 06 '16 at 20:22
  • So, the install is not getting the install path correct and is adding a symlink where? This is incorrect `[sysadmin@node1 ~]$ ls -lh /applications/ total 8.0K lrwxrwxrwx. 1 root wheel 25 Dec 7 09:36 JAVA -> /applications/jre1.8.0_77 drwxrwxr--. 6 root wheel 4.0K Mar 21 2016 jre1.8.0_77 ` – Sean Vucich Dec 06 '16 at 20:58