Skip to content
Ansible role for installing Oracle Java
Shell Python
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.
defaults Upgraded default Java version to 11.0.3 (#189) Apr 19, 2019
handlers Initial commit after running ansible-galaxy init Aug 13, 2016
molecule Upgraded default Java version to 11.0.3 (#189) Apr 19, 2019
tasks Dropped Oracle JDK support (#187) Apr 19, 2019
templates Added support for multiline ansible_managed (#119) Apr 18, 2018
.editorconfig Added .editorconfig file (#41) Sep 9, 2016
.gitattributes Standardized .gitattributes across roles (#6) Aug 20, 2016
.gitignore Restored Molecule 1 tests (#97) Jul 30, 2017
.travis.yml Increased minimum Ansible version to 2.6 (#194) Jul 21, 2019
.yamllint Updated Molecule to 2.20.0 (#183) Apr 4, 2019
moleculew Updated moleculew to version 0.9.9 (#146) Sep 16, 2018

Ansible Role: Java

Build Status Ansible Galaxy License

Role to install the Java JDK.

Important: since the 8.0.0 release of this role the Oracle JDK is no longer supported, AdoptOpenJDK is used for all Java versions. Due to this, support for Java 7 has been discontinued.


  • Ansible >= 2.6

  • Linux Distribution

    • Debian Family

      • Debian

        • Jessie (8)
        • Stretch (9)
      • Ubuntu

        • Trusty (14.04)
        • Xenial (16.04)
        • Bionic (18.04)
    • RedHat Family

      • CentOS

        • 6
        • 7
      • Fedora

        • 28
    • SUSE Family

      • openSUSE

        • 15.0
    • Note: other versions are likely to work but have not been tested.

Role Variables

The following variables will change the behavior of this role (default values are shown below):

# Java version number
# Specify '8', '9', '10', '11' or '12' to get the latest patch version of that
# release.
java_version: 'jdk-11.0.3+7'

# Base installation directory for any Java distribution
java_install_dir: '/opt/java'

# Directory to store files downloaded for Java installation on the remote box
java_download_dir: "{{ x_ansible_download_dir | default(ansible_env.HOME + '/.ansible/tmp/downloads') }}"

# Location Java installations packages can be found on the local box
# local packages will be uses in preference to downloading new packages.
java_local_archive_dir: '{{ playbook_dir }}/files'

# Wether to use installation packages in the local archive (if available)
java_use_local_archive: yes

# If this is the default installation, profile scripts will be written to set
# the JAVA_HOME environment variable and add the bin directory to the PATH
# environment variable.
java_is_default_installation: yes

# Name of the group of Ansible facts relating this Java installation.
# Override if you want use this role more than once to install multiple versions
# of Java.
# e.g. java_fact_group_name: java_8
# would change the Java home fact to:
# ansible_local.java_8.general.home
java_fact_group_name: java

# The SHA-256 for the JDK redistributable

# Mirror location for JDK download (e.g.

# File name for the JDK redistributable installation file

# OpenJDK Implementation (hotspot, openj9)
java_implementation: hotspot

# Timeout for JDK download response in seconds
java_download_timeout_seconds: 600

# The timeout for the AdoptOpenJDK API
java_api_timeout_seconds: 30

Example Playbooks

By default this role will install the latest LTS JDK version provided by AdoptOpenJDK that has been tested and is known to work with this role:

- hosts: servers
    - role:

You can install a specific version of the JDK by specifying the java_version.

- hosts: servers
    - role:
      java_version: 'jdk8u212-b03'

Note: with curl and jq you can view the available versions by running the following command:

for ((i = 8; i <= 12; i++)) do (curl --silent http \
  "$i?openjdk_impl=hotspot" \
  | jq --raw-output '.[].release_name'); done

You can install the multiple versions of the JDK by using this role more than once:

- hosts: servers
    - role: ansible-role-java
      java_version: '8'
      java_is_default_installation: no
      java_fact_group_name: java_8

    - role: ansible-role-java
      java_version: '11'
      java_is_default_installation: yes
      java_fact_group_name: java

To perform an offline install, you need to specify a bit more information (i.e. java_redis_filename and java_redis_sha256sum). E.g. to perform an offline install of jdk-11.0.3+7:

# Before performing the offline install, download
# `OpenJDK11U-jdk_x64_linux_hotspot_11.0.3_7.tar.gz` to
# `{{ playbook_dir }}/files/` on the local machine.
- hosts: servers
    - role:
      java_version: 'jdk-11.0.3+7'
      java_redis_filename: 'OpenJDK11U-jdk_x64_linux_hotspot_11.0.3_7.tar.gz'
      java_redis_sha256sum: '23cded2b43261016f0f246c85c8948d4a9b7f2d44988f75dad69723a7a526094'

Role Facts

This role exports the following Ansible facts for use by other roles:


    • e.g. 8u212

    • e.g. /opt/java/jdk8u212

Overriding java_fact_group_name will change the names of the facts e.g.:

java_fact_group_name: java_8

Would change the name of the facts to:

  • ansible_local.java_8.general.version
  • ansible_local.java_8.general.home

More Roles From GantSign

You can find more roles from GantSign on Ansible Galaxy.

Development & Testing

This project uses Molecule to aid in the development and testing; the role is unit tested using Testinfra and pytest.

To develop or test you'll need to have installed the following:

Because the above can be tricky to install, this project includes Molecule Wrapper. Molecule Wrapper is a shell script that installs Molecule and it's dependencies (apart from Linux) and then executes Molecule with the command you pass it.

To test this role using Molecule Wrapper run the following command from the project root:

./moleculew test

Note: some of the dependencies need sudo permission to install.



Author Information

John Freeman

GantSign Ltd. Company No. 06109112 (registered in England)

You can’t perform that action at this time.