-
-
Save andershedstrom/7c7d0bb5b9450c54a907 to your computer and use it in GitHub Desktop.
--- | |
- hosts: app | |
remote_user: vagrant | |
sudo: yes | |
vars: | |
download_url: http://download.oracle.com/otn-pub/java/jdk/8u5-b13/jdk-8u5-linux-x64.tar.gz | |
download_folder: /opt | |
java_name: "{{download_folder}}/jdk1.8.0_05" | |
java_archive: "{{download_folder}}/jdk-8u5-linux-x64.tar.gz" | |
tasks: | |
- name: Download Java | |
command: "wget -q -O {{java_archive}} --no-check-certificate --no-cookies --header 'Cookie: oraclelicense=accept-securebackup-cookie' {{download_url}} creates={{java_archive}}" | |
- name: Unpack archive | |
command: "tar -zxf {{java_archive}} -C {{download_folder}} creates={{java_name}}" | |
- name: Fix ownership | |
file: state=directory path={{java_name}} owner=root group=root recurse=yes | |
- name: Make Java available for system | |
command: 'alternatives --install "/usr/bin/java" "java" "{{java_name}}/bin/java" 2000' | |
- name: Clean up | |
file: state=absent path={{java_archive}} |
I just made some minor changes and this works for me.
-
name: Creates Directory structure
file:
path: /opt/oracle
state: directory
owner: ec2-user
group: ec2-user
mode: 0755
become: true -
name: Creates Directory structure
file:
path: /opt/oracle/jdk1.8.0_131
state: directory
owner: ec2-user
group: ec2-user
mode: 0755
become: true -
name: Download Java
get_url: url={{ jdk_tarball_url }} dest={{ java_archive }} headers="Cookie:' gpw_e24=http%3A%2F%2Fwww.oracle.com%2F; oraclelicense=accept-securebackup-cookie'" validate_certs=no owner=root group=root mode=744 -
name: Unpack archive
unarchive: copy=no src={{ download_folder }}/{{ jdk_archive }} dest={{download_folder}} -
name: Fix ownership
file: state=directory path={{java_name}} owner=root group=root recurse=yes -
name: Make Java available for system by updating alternatives
command: alternatives --install /usr/bin/java java {{ java_name }}/bin/java 2000
become: true -
name: Make Jar available for system by updating alternatives
command: alternatives --install /usr/bin/jar jar {{ java_name }}/bin/jar 2
become: true -
name: Make Javac available for system by updating alternatives
command: alternatives --install /usr/bin/javac javac {{ java_name }}/bin/javac 2
become: true -
name: Make Jar available for system by updating alternatives
command: alternatives --set jar {{ java_name }}/bin/jar
become: true -
name: Make Javac available for system by updating alternatives
command: alternatives --set javac {{ java_name }}/bin/javac
become: true -
name: Set systemwide oracle env file under /etc/profile.d/
set_fact: remote_file_path={{profile_path}}/oracle_jdk.sh
Create a blank file
- name: Create a new file {{ profile_path }}/oracle_jdk.sh
file: path={{ remote_file_path }} state=touch
Check remote file
- stat: path={{ remote_file_path }}
register: file_path
Copy /etc/profile.d/oracle_jdk.sh with content
- copy:
content: |
export JDK_HOME={{ java_name }}
export JAVA_HOME={{ java_name }}
export JRE_HOME={{ java_name }}/jre
export PATH=$PATH:{{ java_name }}/bin:{{ java_name }}/jre/bin
dest: /etc/profile.d/oracle_jdk.sh
Fix the executable permission
- name: Set executable perission
file: path={{profile_path}}/oracle_jdk.sh owner=root group=root mode=0555 state=file recurse=no
Export the env on th fly to make system wide change
- name: Source the file {{profile_path}}/oracle_jdk.sh
action: shell source /etc/profile
Could you please share Java installation by using tar file with Ansible playbook and update paths in all VMS?
I got this error on executing:
fatal: [localhost]: FAILED! => {"changed": true, "cmd": ["wget", "-q", "-O", "/opt/jdk-8u5-linux-x64.tar.gz", "--no-check-certificate", "--no-cookies", "--header", "Cookie: oraclelicense=accept-securebackup-cookie", "http://download.oracle.com/otn-pub/java/jdk/8u5-b13/jdk-8u5-linux-x64.tar.gz"], "delta": "0:00:04.139554", "end": "2019-02-05 05:39:55.111171", "msg": "non-zero return code", "rc": 8, "start": "2019-02-05 05:39:50.971617", "stderr": "", "stderr_lines": [], "stdout": "", "stdout_lines": []}
This is perfectly working for me.
This one is custom with tar.gz file and plenty of other variables needs cleanup.
Working on CentOS7 and RHEL7 but run at your own risk.
https://github.com/girishkg/ansible/blob/master/playbooks/oracle/oracle_jdk_1.8-playbook.yml