Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Ansible playbook for installing Oracle Java 8 on CentOS
---
- 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}}

robi56 commented Feb 7, 2016

--- 
 - hosts: webservers
   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_65_ansiblecheck"
    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-coo$
   - name: Unpack Archive
     command: "tar -zxf {{java_archive}} -C {{download_folder}} creates={{java_name}}"

i try by this
but it show the error

ERROR: Syntax Error while loading YAML script, installejava.yaml
Note: The error may actually appear before this position: line 14, column 16

   - name: Unpack Archive
     command: "tar -zxf {{java_archive}} -C {{download_folder}} creates={{java_name}}"
               ^
We could be wrong, but this one looks like it might be an issue with
missing quotes.  Always quote template expression brackets when they 
start a value. For instance:            

    with_items:
      - {{ foo }}

Should be written as:

    with_items:
      - "{{ foo }}"  

digicyc commented Mar 6, 2016

If that's an exact copy & paste of your playbook then it looks like you're missing some things on the wget play to Download Java. You'll notice it's cut off at the end.

faizan80 commented Feb 8, 2017

How can I acquire a JDK download URL.
e.g. I need it for u77 version of jdk8

jeanpaulazara commented Mar 6, 2017

I am facing following error while using this playbook (modified accordingly):
fatal: [ec2-52-34-61-252.us-west-2.compute.amazonaws.com]: FAILED! => {"changed": false, "cmd": "alternatives --install /usr/bin/java java /opt/jdk1.8.0_05/bin/java 2000", "failed": true, "msg": "[Errno 2] No such file or directory", "rc": 2}

I have confirmed that the directories specified are present in the VM(SUSE Linux) but it is still throwing the same error

I am using following playbook link
Is there anything I am missing?

Hi, It is not working for me. Below are the logs
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}}

TASK [Download Java] ***********************************************************
task path: /etc/ansible/java_install.yaml:13
Using module file /usr/lib/python2.6/site-packages/ansible/modules/core/commands/command.py
<192.168.99.100> ESTABLISH SSH CONNECTION FOR USER: root
<192.168.99.100> SSH: EXEC sshpass -d15 ssh -C -o ControlMaster=auto -o ControlPersist=60s -o Port=22 -o User=root -o ConnectTimeout=1000 -o ControlPath=/root/.ansible/cp/ansible-ssh-%h-%p-%r 192.168.99.100 '/bin/sh -c '"'"'( umask 77 && mkdir -p "echo $HOME/.ansible/tmp/ansible-tmp-1493132074.22-2111796574868" && echo ansible-tmp-1493132074.22-2111796574868="echo $HOME/.ansible/tmp/ansible-tmp-1493132074.22-2111796574868" ) && sleep 0'"'"''
<192.168.99.100> PUT /tmp/tmp59fFYe TO /root/.ansible/tmp/ansible-tmp-1493132074.22-2111796574868/command.py
<192.168.99.100> SSH: EXEC sshpass -d15 sftp -o BatchMode=no -b - -C -o ControlMaster=auto -o ControlPersist=60s -o Port=22 -o User=root -o ConnectTimeout=1000 -o ControlPath=/root/.ansible/cp/ansible-ssh-%h-%p-%r '[192.168.99.100]'
<192.168.99.100> ESTABLISH SSH CONNECTION FOR USER: root
<192.168.99.100> SSH: EXEC sshpass -d15 ssh -C -o ControlMaster=auto -o ControlPersist=60s -o Port=22 -o User=root -o ConnectTimeout=1000 -o ControlPath=/root/.ansible/cp/ansible-ssh-%h-%p-%r 192.168.99.100 '/bin/sh -c '"'"'chmod u+x /root/.ansible/tmp/ansible-tmp-1493132074.22-2111796574868/ /root/.ansible/tmp/ansible-tmp-1493132074.22-2111796574868/command.py && sleep 0'"'"''
<192.168.99.100> ESTABLISH SSH CONNECTION FOR USER: root
<192.168.99.100> SSH: EXEC sshpass -d15 ssh -C -o ControlMaster=auto -o ControlPersist=60s -o Port=22 -o User=root -o ConnectTimeout=1000 -o ControlPath=/root/.ansible/cp/ansible-ssh-%h-%p-%r -tt 192.168.99.100 '/bin/sh -c '"'"'/usr/bin/python /root/.ansible/tmp/ansible-tmp-1493132074.22-2111796574868/command.py; rm -rf "/root/.ansible/tmp/ansible-tmp-1493132074.22-2111796574868/" > /dev/null 2>&1 && sleep 0'"'"''
fatal: [192.168.99.100]: 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:00.388364",
"end": "2017-04-25 20:24:35.784464",
"failed": true,
"invocation": {
"module_args": {
"_raw_params": "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",
"_uses_shell": false,
"chdir": null,
"creates": "/opt/jdk-8u5-linux-x64.tar.gz",
"executable": null,
"removes": null,
"warn": true
},
"module_name": "command"
},
"rc": 6,
"start": "2017-04-25 20:24:35.396100",
"stderr": "",
"stdout": "",
"stdout_lines": [],
"warnings": [

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment