I am having syntax errors and I am unsure how to resolve them. In the roles file I have defined the fallowing:
default_attributes(
\'jdk\' => {
\'v
You should escape all double quotes in your command string, because it starts and ends with double quotes.
There is no action :creates for execute resource. The action should be :run.
execute "update_alt_java" do
command "update-alternatives --install \"/usr/bin/java\" \"java\" \"#{node['java']['home']}/bin/java\" 1"
action :run
end
But you don't want to run this resource on every chef run, so you should come up with some kind of condition, when it should be run (using only_if, not_if statements).
Are you using the community java cookbook?
It includes an LWRP for this purpose:
# set alternatives for java and javac commands
java_alternatives "set java alternatives" do
java_location '/usr/local/java'
bin_cmds ["java", "javac"]
action :set
end
The following is a sample cookbook called "my_java" designed to install the oracle JDK on Ubuntu:
├── attributes
│ └── java.rb <-- Used for java cookbook attribute overrides
├── Berksfile
├── Berksfile.lock
├── metadata.rb
├── README.md
└── recipes
└── default.rb
After running chef the oracle JDK is intalled
$ java -version
java version "1.8.0_31"
Java(TM) SE Runtime Environment (build 1.8.0_31-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.31-b07, mixed mode)
Notes:
name 'my_java'
maintainer 'Mark O''Connor'
maintainer_email 'XXXXXXXXXXXXXXX'
license 'All rights reserved'
description 'Installs/Configures my_java'
long_description 'Installs/Configures my_java'
version '0.1.0'
depends "apt"
depends "java"
normal['java']['jdk_version'] = '8'
normal['java']['install_flavor'] = 'oracle'
normal['java']['oracle']['accept_oracle_download_terms'] = true
Notes:
include_recipe "apt"
include_recipe "java"
Notes: