gantsign.java

Ansible Role: Java

This role helps you install the Java JDK.

Requirements

  • Ansible Core version must be 2.12 or higher.

  • Linux Distribution:

    • Debian Family:

      • Debian:

        • 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.4
    • Note: Other versions may work but haven't been tested.

Role Variables

You can adjust the following settings (default values are shown):

# Specify the Java version you want: '8', '11', '17', or '21'.
java_version: '21.0.2+13'

# Directory for Java installation
java_install_dir: '/opt/java'

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

# Path where local Java packages are stored
java_local_archive_dir: '{{ playbook_dir }}/files'

# Should local packages be used (if available)?
java_use_local_archive: true

# If this is the default installation, environment variables will be set.
java_is_default_installation: true

# Name of the group for this Java installation facts.
java_fact_group_name: java

# The SHA-256 hash for the JDK file
java_redis_sha256sum:

# Link to download JDK (e.g., https://example.com)
java_redis_mirror:

# File name of the JDK installation file
java_redis_filename:

# JDK download timeout in seconds
java_download_timeout_seconds: 600

# Timeout for the Adoptium API
java_api_timeout_seconds: 30

Example Playbooks

By default, this role installs the latest Long-Term Support (LTS) JDK version from Adoptium:

- hosts: servers
  roles:
    - role: gantsign.java

To install a specific JDK version, set the java_version:

- hosts: servers
  roles:
    - role: gantsign.java
      java_version: '8.0.402+6'

Note: Use curl and jq to check available versions:

for i in 21 17 11 8; do (curl --silent http \
  "https://api.adoptium.net/v3/info/release_names?version=%5B$i,$(($i + 1)))\
&release_type=ga" | jq --raw-output '.releases[]' | sed -E 's/^jdk\-?//'); done

To install multiple JDK versions, use this role multiple times:

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

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

For an offline install, you need to provide more details (java_major_version, java_release_name, java_redis_filename, and java_redis_sha256sum). For example:

# Download `OpenJDK11U-jdk_x64_linux_hotspot_11.0.22_7.tar.gz`
# to `{{ playbook_dir }}/files/` first.
- hosts: servers
  roles:
    - role: gantsign.java
      java_major_version: '11'
      java_version: '11.0.22+7'
      java_release_name: 'jdk-11.0.22+7'
      java_redis_filename: 'OpenJDK11U-jdk_x64_linux_hotspot_11.0.22_7.tar.gz'
      java_redis_sha256sum: '25cf602cac350ef36067560a4e8042919f3be973d419eac4d839e2e0000b2cc8'

Role Facts

This role provides the following information for use by other roles:

  • ansible_local.java.general.version (e.g., 8u402)
  • ansible_local.java.general.home (e.g., /opt/java/jdk8u402)

Changing java_fact_group_name will modify the fact names. For example:

java_fact_group_name: java_8

This would change the fact names to:

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

More Roles From GantSign

Visit Ansible Galaxy for more roles from GantSign.

Development & Testing

This project uses:

  • Molecule for testing scenarios
  • Testinfra for testing changes remotely
  • pytest for the testing framework
  • Tox for managing Python environments
  • pip-tools for dependency management

A Visual Studio Code Dev Container is available for development and testing.

License

MIT License

Author Information

John Freeman

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

Informazioni sul progetto

Role for installing the Java JDK.

Installa
ansible-galaxy install gantsign.java
Licenza
mit
Download
149.3k
Proprietario