# Install Java using its source :: Ansible

**URL:** <https://forum.ansible.com/t/install-java-using-its-source-ansible/26006>\
**Category:** Ansible Project\
**Created:** [November 13, 2017, 3:57am UTC](https://forum.ansible.com/t/install-java-using-its-source-ansible/26006 "2017-11-13T03:57:18Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![luke.devon80](https://avatars.discourse-cdn.com/v4/letter/l/ce7236/32.png) [@luke.devon80](https://forum.ansible.com/u/luke.devon80)\
**Post date:** [November 13, 2017, 3:57am UTC](https://forum.ansible.com/t/install-java-using-its-source-ansible/26006/1 "2017-11-13T03:57:18Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Dick\_Visser](https://avatars.discourse-cdn.com/v4/letter/d/d9b06d/32.png) [@Dick\_Visser](https://forum.ansible.com/u/Dick_Visser)\
**Post date:** [November 13, 2017, 6:01am UTC](https://forum.ansible.com/t/install-java-using-its-source-ansible/26006/2 "2017-11-13T06:01:14Z")

</div>

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](https://github.com/frieder/ansible-role-oraclejdk/blob/master/README.md).

Dick

---

<div class="post-metadata">

**Author:** ![Soniya\_panwar](https://avatars.discourse-cdn.com/v4/letter/s/22d042/32.png) [@Soniya\_panwar](https://forum.ansible.com/u/Soniya_panwar)\
**Post date:** [November 14, 2017, 11:21am UTC](https://forum.ansible.com/t/install-java-using-its-source-ansible/26006/3 "2017-11-14T11:21:30Z")

</div>

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”

1. 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.

---

<div class="post-metadata">

**Author:** ![Soniya\_panwar](https://avatars.discourse-cdn.com/v4/letter/s/22d042/32.png) [@Soniya\_panwar](https://forum.ansible.com/u/Soniya_panwar)\
**Post date:** [November 15, 2017, 6:34am UTC](https://forum.ansible.com/t/install-java-using-its-source-ansible/26006/4 "2017-11-15T06:34:45Z")

</div>

> 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

---

<div class="post-metadata">

**Author:** ![luke.devon80](https://avatars.discourse-cdn.com/v4/letter/l/ce7236/32.png) [@luke.devon80](https://forum.ansible.com/u/luke.devon80)\
**Post date:** [November 17, 2017, 6:51am UTC](https://forum.ansible.com/t/install-java-using-its-source-ansible/26006/5 "2017-11-17T06:51:49Z")

</div>

Thank you all , All your guides are helpful and I was able to achieve my requirement.

Regards  
Luke.
