Skip to content

Commit a002912

Browse files
committed
Added oracle-java role for ansible-galaxy
1 parent e8b17d5 commit a002912

File tree

8 files changed

+137
-1
lines changed

8 files changed

+137
-1
lines changed

LICENSE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) [2017] [Avinash Pawar]
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

+41-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,41 @@
1-
# ansible-oracle-java
1+
# Ansible Role: Oracle Java [Ansible Playbook Role To Install Java]
2+
3+
Install Oracle Java 1.8, a distributed version control system, on any RHEL/CentOS Linux system.
4+
5+
## Requirements
6+
7+
None.
8+
9+
## Role Variables
10+
None
11+
12+
## Dependencies
13+
14+
None.
15+
16+
## Usage and Example Playbook
17+
18+
Install from Ansible Galaxy
19+
20+
$ ansible-galaxy install avinash6784.oracle-java
21+
Or download manually
22+
23+
$ git clone https://github.com/avinash6784/ansible-oracle-java.git
24+
The code should reside in the roles directory of ansible ( See ansible documentation for more information on roles ), in a folder oracle-java.
25+
26+
## Run the playbook
27+
28+
First create a playbook including the git role, naming it java.yml.
29+
```yml
30+
- name: Install Oracle Java
31+
hosts: java
32+
become: true
33+
roles:
34+
- oracle-java
35+
36+
$ ansible-playbook -i hosts java.yml
37+
```
38+
39+
## Author Informations
40+
41+
This role was created by [Avinash Pawar](https://github.com/avinash6784/ansible-oracle-java).

defaults/main.yml

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
#Role Java vars
3+
4+
download_url: http://download.oracle.com/otn-pub/java/jdk/8u111-b14/jdk-8u111-linux-x64.tar.gz
5+
download_folder: /opt
6+
java_name: "{{download_folder}}/jdk1.8.0_111"
7+
java_archive: "{{download_folder}}/jdk-8u111-linux-x64.tar.gz"
8+
java_env_file: "/etc/profile.d/java.sh"
9+
java_home: /opt/jdk1.8.0_111

meta/main.yml

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
---
2+
dependencies: []
3+
4+
galaxy_info:
5+
author: avinash6784 (Avinash Pawar)
6+
description: Ansible role to install Oracle Java
7+
license: MIT
8+
company: "DevOps Techie"
9+
min_ansible_version: 2.0
10+
platforms:
11+
- name: EL
12+
versions:
13+
- all
14+
galaxy_tags:
15+
- development
16+
- system

tasks/main.yml

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
---
2+
3+
# Ansible role to install Oracle Java 7
4+
5+
- name: Check If java is already installed or not
6+
shell: "{{ java_name }}/bin/java -version 2>&1 | grep version | awk '{print $3}' | sed 's/\"//g'"
7+
register: java_installed
8+
9+
- name: Installed java version
10+
debug: "msg={{java_installed.stdout}}"
11+
12+
- block:
13+
- name: Download Java
14+
#command: "wget -q -O {{java_archive}} --no-check-certificate --no-cookies --header 'Cookie: oraclelicense=accept-securebackup-cookie' {{download_url}} creates={{java_archive}}" ## Old way to download
15+
get_url:
16+
url: "{{download_url}}"
17+
dest: "{{java_archive}}"
18+
headers: 'Cookie: gpw_e24=http%3A%2F%2Fwww.oracle.com%2F; oraclelicense=accept-securebackup-cookie; --no-check-certificate'
19+
20+
- name: Unpack archive
21+
#command: "tar -zxf {{java_archive}} -C {{download_folder}} creates={{java_name}}" ## Old way to untar
22+
unarchive:
23+
src: "{{java_archive}}"
24+
dest: "{{download_folder}}"
25+
remote_src: yes
26+
27+
- name: Fix ownership
28+
file: state=directory path={{java_name}} owner=root group=root recurse=yes
29+
30+
- name: Make Java available for system
31+
command: 'alternatives --install "/usr/bin/java" "java" "{{java_name}}/bin/java" 2000'
32+
33+
- name: Set/Configure JAVA_HOME in environment variables
34+
shell: "echo 'export JAVA_HOME={{java_name}}\n export PATH=$JAVA_HOME/bin:$PATH' > {{java_env_file}}"
35+
36+
- name: Exports/Run java env file for make JAVA_HOME available globally
37+
shell: "source {{java_env_file}}"
38+
39+
- name: Clean up
40+
file: state=absent path={{java_archive}}
41+
42+
when: java_installed.stdout == ""

tests/inventory

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
localhost

tests/test.yml

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
- hosts: localhost
3+
become: true
4+
roles:
5+
- { role: oracle-java }

vars/main.yml

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
---
2+
#Role Java vars

0 commit comments

Comments
 (0)