Install Java using its source :: Ansible

142 views
Skip to first unread message

luke.d...@gmail.com

unread,
Nov 12, 2017, 10:57:18 PM11/12/17
to Ansible Project
Hi 

I want to install java using its source (tar.gz) for number of redhat servers . Can you please give me a little guide ? How can I use ansible for this task and what are the command list ?

For example : I have 10 no.of redhat 7.2 servers and I want to install   jdk-9.0.1_linux-x64_bin.tar.gz for all those servers and same time i wanna setup the java class path too.


Thank you
Luke

Dick Visser

unread,
Nov 13, 2017, 1:01:38 AM11/13/17
to ansible...@googlegroups.com
You could write up everything from scratch. But since this is a common requirement many people have already done that.
I would just use one of those roles, for instance https://github.com/frieder/ansible-role-oraclejdk/blob/master/README.md.

Dick

--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/3a88589e-e017-4b20-a926-b7f08986ca6a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--
Dick Visser
GÉANT

Want to join us? We're hiring: https://www.geant.org/jobs

Soniya panwar

unread,
Nov 14, 2017, 6:21:30 AM11/14/17
to Ansible Project
Hello,
>> I have 10 no.of redhat 7.2 servers and I want to install   jdk-9.0.1_linux-x64_bin.tar.gz for all those servers and same time i wanna setup the java class path too.

you can achieve this task by following these options:

1) First of all you have to do the entry of your 10 redhat server in "/etc/ansible/hosts" file.
e.g;
[ RedhatServer ]
RedhatServer1
RedhatServer2
. . .
. . .
RedhatServer10

2) make above servers passwordless by using Openssh
eg;

step1: generate ssh key on your machine 
$ ssh-keygen

Step2: Copy your public key to the servers with ssh-copy-id:
$ ssh-copy-id -i ~/.ssh/id_rsa.pub "name@RedhatServer1"

3) use below playbook to deploy Java on all the given machines using source ( tar.gz):

  • It will first download Java by using get_url module in /java folder (you can give your own folder name here).
  • Then it will extract the java tar file by using unarchive module within the java folder.
  • After extracting it will set the classpath to java.


---
- hosts: RedhatServer

  tasks:
  - name: Download Java
    get_url:
      dest: /java
      headers: Cookie: oraclelicense=accept-securebackup-cookie
     
 - name: Extract jdk-9.0.1_linux-x64_bin.tar.gz into /java
   unarchive:
    src: /java/jdk-9.0.1_linux-x64_bin.tar.gz
    dest: /java

  - name: setup the java class path
    command: export CLASSPATH="your classpath"


Thanks 
Soniya

Soniya panwar

unread,
Nov 15, 2017, 1:34:45 AM11/15/17
to Ansible Project
Hello,

Above provided playbook will set the Classpath temporaily. 
If you wish to make the entry persistent, you will have to use below task  in place of  "setup the java class path" task:

  - name: setup the java Classpath permanently 
    lineinfile:
     path: ~/.bashrc
     line: 'export CLASSPATH="/java":"/java":"${CLASSPATH}"' 

Thanks 
Soniya

luke.d...@gmail.com

unread,
Nov 17, 2017, 1:51:49 AM11/17/17
to Ansible Project
Thank you all , All your guides are helpful and I was able to achieve my requirement.

Regards
Luke.
Reply all
Reply to author
Forward
0 new messages