My Chef recipe does what I want it to do except there is an error when Chef-client completes.
Should I ignore the error or be alarmed? I would like to get rid of the error, but it will not bother me that much. My Chef recipe installs Java. Here is the error and related output:
================================================================================
Error executing action create
on resource ‘ruby_block[update-java-alternatives]’
================================================================================
TypeError
---------
no implicit conversion of nil into String
Cookbook Trace:
---------------
/var/chef/cache/cookbooks/java/recipes/openjdk.rb:63:in `block (2 levels) in from_file'
Resource Declaration:
---------------------
# In /var/chef/cache/cookbooks/java/recipes/openjdk.rb
43: ruby_block "update-java-alternatives" do
44: block do
45: if platform?("ubuntu", "debian") and version == 8
46: run_context = Chef::RunContext.new(node, {})
47: r = Chef::Resource::Execute.new("update-java-alternatives", run_context)
48: r.command "update-java-alternatives -s java-8-openjdk"
49: r.returns [0,2]
50: r.run_action(:create)
51: else
52: # have to do this on ubuntu for version 7 because Ubuntu does
53: # not currently set jdk 7 as the default jvm on installation
54: require "fileutils"
55: arch = node['kernel']['machine'] =~ /x86_64/ ? "x86_64" : "i386"
56: Chef::Log.debug("glob is #{java_home_parent}/java*#{version}*openjdk*")
57: jdk_home = Dir.glob("#{java_home_parent}/java*#{version}*openjdk{,[-\.]#{arch}}")[0]
58: Chef::Log.debug("jdk_home is #{jdk_home}")
59: # delete the symlink if it already exists
60: if File.exists? java_home
61: FileUtils.rm_f java_home
62: end
63: FileUtils.ln_sf jdk_home, java_home
64:
65: cmd = Chef::ShellOut.new(
66: %Q[ update-alternatives --install /usr/bin/java java #{java_home}/bin/java 1;
67: update-alternatives --set java #{java_home}/bin/java ]
68: ).run_command
69: unless cmd.exitstatus == 0 or cmd.exitstatus == 2
70: Chef::Application.fatal!("Failed to update-alternatives for openjdk!")
71: end
72: end
73: end
Compiled Resource:
------------------
# Declared in /var/chef/cache/cookbooks/java/recipes/openjdk.rb:43:in `from_file'
ruby_block("update-java-alternatives") do
action [:nothing]
default_guard_interpreter :default
block_name "update-java-alternatives"
declared_type :ruby_block
cookbook_name "java"
recipe_name "openjdk"
block #<Proc:0x0000000003112c10@/var/chef/cache/cookbooks/java/recipes/openjdk.rb:44>
end
System Info:
------------
chef_version=13.6.4
platform=ubuntu
platform_version=16.04
ruby=ruby 2.4.2p198 (2017-09-14 revision 59899) [x86_64-linux]
program_name=chef-client worker: ppid=26832;start=03:17:15;
executable=/opt/chef/bin/chef-client