Verify the java on chef-node

Hi @Larryc

I am trying to verify the installation of java on chef-node. If it is not installed, then install it.

I am doing the same through two separate recipes.
The First recipe is verifying the java on chef node:

execute "Validate Java" do
	command "java -version"
end

If the response of the first recipe is failed then another recipe will install it.

# Download Java_8 from a remote directory on the chef-client node
remote_file "#{Chef::Config['file_cache_path']}/jdk-8u181-windows-x64.exe" do
  source  "#{node['shared_resources']['java_8']['download_url']}"
  remote_domain "#{node['shared_resources']['domain']}"
  remote_user "#{node['shared_resources']['user_name']}"
  remote_password "#{node['shared_resources']['password']}"
end

execute "Java_8" do
	cwd "#{Chef::Config['file_cache_path']}"
	command "jdk-8u181-windows-x64.exe"
end

but I want to do the same (verify and installation of java) in one recipe. I don't know how to handle the error response within the recipe if java is not installed.

Thanks
Deepak

Could do something like this

Download Java_8 from a remote directory on the chef-client node

remote_file "#{Chef::Config['file_cache_path']}/jdk-8u181-windows-x64.exe" do
source "#{node['shared_resources']['java_8']['download_url']}"
remote_domain "#{node['shared_resources']['domain']}"
remote_user "#{node['shared_resources']['user_name']}"
remote_password "#{node['shared_resources']['password']}"
not_if { ::Directory.exist?( %JAVA_HOME% )}
end

execute "Java_8" do
cwd "#{Chef::Config['file_cache_path']}"
not_if { ::Directory.exist?( %JAVA_HOME% )}
command "jdk-8u181-windows-x64.exe"
end

Hi @Larryc

Instead to check the existence of "Java_Home" directory, is there any way to verify through command?

command "java -version" 

If command is executed properly, then no need to install the java, otherwise install it.