2

I'm trying to install Java JDK 1.8 on CentOS 7 using a Chef Cookbook.

I'm using Chef DK on Windows 10 and I've donloaded from https://downloads.chef.io/chefdk

In my Berksfile I've

source 'https://supermarket.chef.io'
metadata  

My Kitchen.yml is the follow

---
driver:
  name: vagrant

provisioner:
  name: chef_zero
  # You may wish to disable always updating cookbooks in CI or other testing environments.
  # For example:
  #   always_update_cookbooks: <%= !ENV['CI'] %>
  always_update_cookbooks: true

verifier:
  name: inspec

platforms:
  - name: centos-7

suites:
  - name: default
    run_list:
      - recipe[test::default]
    verifier:
      inspec_tests:
        - test/integration/default
    attributes:

My metadata.rb is the follow

name 'test'
maintainer 'The Authors'
maintainer_email 'you@example.com'
license 'All Rights Reserved'
description 'Installs/Configures test'
long_description 'Installs/Configures test'
version '0.1.0'
chef_version '>= 12.14' if respond_to?(:chef_version)

depends 'java', '~> 2.2.0'

My recipes/default.rb

node.default["java"]["install_flavor"] = "oracle"
node.default["java"]["jdk_version"]    = "8"
node.default['java']['oracle']['accept_oracle_download_terms'] = true

include_recipe "java"

and its attributes/recipe.rb

default['java']['install_flavor'] = 'oracle'
default['java']['jdk_version'] = '8'
default['java']['oracle']['accept_oracle_download_terms'] = true

When I try to execute kitchen converge the output is

-----> Starting Kitchen (v1.22.0)
-----> Converging <default-centos-7>...
       Preparing files for transfer
       Preparing dna.json
       Resolving cookbook dependencies with Berkshelf 7.0.4...
       Removing non-cookbook files before transfer
       Preparing validation.pem
       Preparing client.rb
-----> Chef Omnibus installation detected (install only if missing)
       Transferring files to <default-centos-7>
       Starting Chef Client, version 14.3.37
       resolving cookbooks for run list: ["test::default"]
       Synchronizing Cookbooks:
         - windows (5.0.0)
         - homebrew (5.0.4)
         - test (0.1.0)
         - java (2.2.0)
       Installing Cookbook Gems:
       Compiling Cookbooks...

       ================================================================================
       Recipe Compile Error in /tmp/kitchen/cache/cookbooks/test/recipes/default.rb
       ================================================================================

       NoMethodError
       -------------
       undefined method `java_oracle_install' for cookbook: java, recipe: oracle :Chef::Recipe

       Cookbook Trace:
       ---------------
         /tmp/kitchen/cache/cookbooks/java/recipes/oracle.rb:40:in `from_file'
         /tmp/kitchen/cache/cookbooks/java/recipes/default.rb:22:in `from_file'
         /tmp/kitchen/cache/cookbooks/test/recipes/default.rb:8:in `from_file'

       Relevant File Content:
       ----------------------
       /tmp/kitchen/cache/cookbooks/java/recipes/oracle.rb:

        33:  version = node['java']['jdk_version'].to_s
        34:  tarball_url = node['java']['jdk'][version][arch]['url']
        35:  tarball_checksum = node['java']['jdk'][version][arch]['checksum']
        36:  bin_cmds = node['java']['jdk'][version]['bin_cmds']
        37:
        38:  include_recipe 'java::set_java_home'
        39:
        40>> java_oracle_install 'jdk' do
        41:    url tarball_url
        42:    default node['java']['set_default']
        43:    checksum tarball_checksum
        44:    app_home java_home
        45:    bin_cmds bin_cmds
        46:    alternatives_priority node['java']['alternatives_priority']
        47:    retries node['java']['ark_retries']
        48:    retry_delay node['java']['ark_retry_delay']
        49:    connect_timeout node['java']['ark_timeout']

       System Info:
       ------------
       chef_version=14.3.37
       platform=centos
       platform_version=7.5.1804
       ruby=ruby 2.5.1p57 (2018-03-29 revision 63029) [x86_64-linux]
       program_name=/opt/chef/bin/chef-client
       executable=/opt/chef/bin/chef-client


       Running handlers:
       [2018-08-21T17:23:54+00:00] ERROR: Running exception handlers
       [2018-08-21T17:23:54+00:00] ERROR: Running exception handlers
       Running handlers complete
       [2018-08-21T17:23:54+00:00] ERROR: Exception handlers complete
       [2018-08-21T17:23:54+00:00] ERROR: Exception handlers complete
       Chef Client failed. 0 resources updated in 04 seconds
       [2018-08-21T17:23:54+00:00] FATAL: Stacktrace dumped to /tmp/kitchen/cache/chef-stacktrace.out
       [2018-08-21T17:23:54+00:00] FATAL: Stacktrace dumped to /tmp/kitchen/cache/chef-stacktrace.out
       [2018-08-21T17:23:54+00:00] FATAL: Please provide the contents of the stacktrace.out file if you file a bug report
       [2018-08-21T17:23:54+00:00] FATAL: Please provide the contents of the stacktrace.out file if you file a bug report
       [2018-08-21T17:23:54+00:00] FATAL: NoMethodError: undefined method `java_oracle_install' for cookbook: java, recipe: oracle :Chef::Recipe
       [2018-08-21T17:23:54+00:00] FATAL: NoMethodError: undefined method `java_oracle_install' for cookbook: java, recipe: oracle :Chef::Recipe
>>>>>> ------Exception-------
>>>>>> Class: Kitchen::ActionFailed
>>>>>> Message: 1 actions failed.
>>>>>>     Converge failed on instance <default-centos-7>.  Please see .kitchen/logs/default-centos-7.log for more details
>>>>>> ----------------------
>>>>>> Please see .kitchen/logs/kitchen.log for more details
>>>>>> Also try running `kitchen diagnose --all` for configuration

Any suggestions?

Vyacheslav
  • 156
  • 1
  • 1
  • 10
Cesare
  • 1,629
  • 9
  • 30
  • 72
  • I have tried to reproduce your error, but without luck, centos 7.5 (I think it is the same image as centos 7), java cookbook 2.2.0, chef 14.3.37 :/ The only difference in my case is newer version of test-kitchen (1.23.2). Have you tried different version of chefdk? I do not see anything particular in chefdk or test-kitchen changelogs but I am out of ideas. – Szymon Aug 22 '18 at 06:54
  • I'm using Chef DK on Windows and I've download ed it from official site... how may I update my test kitchen version? – Cesare Aug 22 '18 at 07:56
  • 1
    I am not sure, I do not use chefdk. You may try to ask on [Chef's slack #chef-dk or #general channel](https://community-slack.chef.io/). – Szymon Aug 22 '18 at 11:36

1 Answers1

1

After several attempts (supported also by the Slack Chef chat ...), I've solved: I'm not sure how general is this solution but it works.

The problem is a about execution of the command kitchen converge.

I've noticed that when it fails with the message warning: conflicting chdir during another chdir block this generate (I don't kno why ...), INSIDE the cookbook some directories (in my case, java, windows, homebrew, ecc .. ), and this was quite strange.

What I've done:

  1. Submit the command kitchen destroy
  2. Cleared out my berks cache C:\Users\USERNAME\.berkshelf
  3. Submit the command kitchen create
  4. Submit the command kitchen converge
  5. If the error warning: conflicting chdir during another chdir block compare and some strange directory is generated inside the cookbook, delete them (MANUALLY).
  6. Check that the Chef supermarket cookbook are downloaded in C:\Users\USERNAME\.berkshelf (in my case homebrew-5.0.4, java-2.2.0, tomcat-3.0.0 and windows-5.0.0)
  7. Repeat the command kitchen converge until no error is generated

In this way oracle java jdk 1.8 has been installed on my CentOS 7 target node

I hope this could be useful for others

Cesare
  • 1,629
  • 9
  • 30
  • 72