itsme
itsme

Reputation: 193

Installing java using chef

I know how to install java on linux machine using terminal. But i want to automate the installation using Chef Framework. I have two machines M1 and M2. I am on machine M1 and want to install java on machine M2. This is what i do in using terminal....

first i SSH into machine M2, after i do the following things... (in here i download the java files from third party storage.)

Step1:-
cd setup

step2:-
wget http://downloads.company.com/downloads/DevTools/jdk/6.0/jdk-6u31-linux-i586.bin

Step3:-
chmod +x jdk-6u31-linux-i586.bin

Step4:-
yes | ./jdk-6u31-linux-i586.bin

Step5:-
cd /usr/bin

Step6:-
mv java javaorg

Step7:-
cd /usr

Step8:-
ln -s /home/harish/setup/jdk1.6.0_31 java

Step9:-
echo 'export PATH=$PATH:/usr/java/bin' > /etc/profile.d/alljava.sh;echo 'export JAVA_BINDIR=/usr/java/bin' >> /etc/profile.d/alljava.sh;echo 'export JAVA_ROOT=/usr/java' >> /etc/profile.d/alljava.sh;echo 'export JAVA_HOME=/usr/java' >> /etc/profile.d/alljava.sh;echo 'export JRE_HOME=/usr/java/jre' >> /etc/profile.d/alljava.sh

Step10:-
source /etc/profile.d/alljava.sh

Step11:-
echo $JAVA_HOME

Step12:-
java -version

I have following questions:

  1. what is the category of the problem (chef-solo or shef-server)
  2. do i need to have machine M2 installed Chef.
  3. i have downloaded the cookbook for JAVA from GitHub but i don't know what to do with that.

i have written some code for installing java on SAME machine.. but it also not working.. CODE:

 #cookbook/java/recipe/default.rb    

    *####This will install JAVA on machine M1######*


    execute "copy" do
      cwd "/home/user/setup"
      command "wget http://downloads.company.com/downloads/DevTools/jdk/6.0/jdk-6u31-linux-i586.bin"
    end
    execute "change_mode" do
      command "chmod +x jdk-6u31-linux-i586.bin"
    end
    execute "dont_know" do
      command "yes | ./jdk-6u31-linux-i586.bin"
    end

    execute "make link" do
      command "ln -s /home/harish/setup/jdk1.6.0_31 java"
    end

    java_home = "export JAVA_HOME=/usr/java/jdk1.6.0_31"
    path = "export PATH=$PATH:JAVA_HOME/bin"

    file "/etc/profile" do
      content "#{java_home}\n#{path}"
      owner "root"
    end

but this code is giving some big messages..(errors). can anybody help through this and also how to use the downloaded cookbooks for JAVA.. thanks. :)

Upvotes: 2

Views: 8231

Answers (1)

Eric
Eric

Reputation: 466

This is a long out-of-date question, but I'll include an answer in case someone stumbles in on this one.

Opscode has a Java cookbook that they maintain that can install either OpenJDK or Oracle JDK. It's available at the opscode community site here.

You can use it by adding a dependency to your cookbook's metadata.rb:

depends "java",     "~> 1.10.2"

and including the recipe in your cookbook's default.rb:

include_recipe "java"

Upvotes: 9

Related Questions