Role to install the Java JDK.
-
Ansible >= 2.9
-
Linux Distribution
-
Debian Family
-
Debian
- Stretch (9)
- Buster (10)
- Bullseye (11)
-
Ubuntu
- Bionic (18.04)
- Focal (20.04)
- Jammy (22.04)
-
-
RedHat Family
-
Rocky Linux
- 8
-
Fedora
- 35
-
-
SUSE Family
-
openSUSE
- 15.3
-
-
Note: other versions are likely to work but have not been tested.
-
The following variables will change the behavior of this role (default values are shown below):
# Java version number
# Specify '8', '11', '17' or '18' to get the latest patch version of that
# release.
java_version: '17.0.4+8'
# 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
java_redis_sha256sum:
# Mirror location for JDK download (e.g. https://example.com/provisioning/files)
java_redis_mirror:
# File name for the JDK redistributable installation file
java_redis_filename:
# Timeout for JDK download response in seconds
java_download_timeout_seconds: 600
# The timeout for the Adoptium API
java_api_timeout_seconds: 30
By default this role will install the latest LTS JDK version provided by Adoptium that has been tested and is known to work with this role:
- hosts: servers
roles:
- role: gantsign.java
You can install a specific version of the JDK by specifying the java_version
.
- hosts: servers
roles:
- role: gantsign.java
java_version: '8.0.342+7'
Note: with curl and jq you can view the available versions by running the following command:
for i in 8 11 17 18; do (curl --silent http \
"https://api.adoptium.net/v3/assets/feature_releases/$i/ga?\
architecture=x64&heap_size=normal&image_type=jdk&jvm_impl=hotspot&\
os=linux&project=jdk&sort_order=DESC&vendor=adoptium" \
| jq --raw-output '.[].version_data.semver'); done
You can install the multiple versions of the JDK by using this role more than once:
- hosts: servers
roles:
- 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_major_version
, java_release_name
, java_redis_filename
and
java_redis_sha256sum
). E.g. to perform an offline install of 11.0.16+8
:
# Before performing the offline install, download
# `OpenJDK11U-jdk_x64_linux_hotspot_11.0.16_8.tar.gz` to
# `{{ playbook_dir }}/files/` on the local machine.
- hosts: servers
roles:
- role: gantsign.java
java_major_version: '11'
java_version: '11.0.16+8'
java_release_name: 'jdk-11.0.16+8'
java_redis_filename: 'OpenJDK11U-jdk_x64_linux_hotspot_11.0.16_8.tar.gz'
java_redis_sha256sum: 'f79506f80c796d8e6a382f00bd8c528a330c5e29581aaf5cb61e1831742d166f'
This role exports the following Ansible facts for use by other roles:
-
ansible_local.java.general.version
- e.g.
8u312
- e.g.
-
ansible_local.java.general.home
- e.g.
/opt/java/jdk8u312
- e.g.
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
You can find more roles from GantSign on Ansible Galaxy.
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.
MIT
John Freeman
GantSign Ltd. Company No. 06109112 (registered in England)