arolfes.graalvm
Ansible Role: GraalVM
This role installs the GraalVM Community Edition (CE).
Requirements
Ansible Version: 5 or higher (Ansible Core: 2.12 or higher)
Supported Linux Distributions:
Debian Family
- Ubuntu: Focal (20.04) and Jammy (22.04)
- Debian: Buster (10), Bullseye (11), Bookworm (12)
RedHat Family
- Fedora: 37 and 38
SUSE Family
- openSUSE: 15.0, 15.1, 15.2, 15.3, 15.4, 15.5
Note: Other versions may work but haven't been tested.
Role Variables
You can customize the behavior of this role using the following variables (default values shown):
# Specify the JDK version (17.0.7, 17.0.8, 20.0.1, 20.0.2, 21.0.0, or 21.0.2)
graalvm_java_version: '21.0.2'
# Base installation directory for GraalVM
graalvm_install_dir: '/opt/graalvm'
# Directory for downloaded files during installation
graalvm_download_dir: "{{ x_ansible_download_dir | default(ansible_env.HOME + '/.ansible/tmp/downloads') }}"
# If this is the default installation, set environment variable for GRAALVM_HOME
graalvm_is_default_installation: true
# If the GraalVM bin directory should be added to the PATH
graalvm_add_to_path: true
# Location of local GraalVM packages on your machine
graalvm_local_archive_dir: '{{ playbook_dir }}/files'
# Use local archived packages if available
graalvm_use_local_archive: true
# The SHA-256 checksum for GraalVM redistributable
graalvm_redis_sha256sum:
# Location for GraalVM download (only if not downloading directly from GitHub)
graalvm_redis_mirror:
# Filename for the GraalVM installation file
graalvm_redis_filename: "graalvm-community-jdk-{{ graalvm_java_version }}_linux-{{ graalvm_architecture }}_bin.tar.gz"
# Group name for Ansible facts related to this GraalVM installation
graalvm_fact_group_name: graalvm
# Timeout for GraalVM download response (in seconds)
graalvm_download_timeout_seconds: 600
# Select the architecture: x64 (amd64) or aarch64
graalvm_architecture: 'x64'
Supported GraalVM Versions
These versions of GraalVM Community JDK are supported:
- 17.0.7
- 17.0.8
- 20.0.1
- 20.0.2
- 21.0.0
- 21.0.2
Supported Architectures
- x64 (amd64)
- aarch64
Example Playbooks
By default, this role installs the latest version of GraalVM CE that is compatible:
- hosts: servers
roles:
- role: arolfes.graalvm
# Results in:
# New file: /etc/profile.d/graalvm.sh
# Content:
# GRAALVM_HOME=/opt/graalvm/jdk-21.0.2
# PATH=${GRAALVM_HOME}/bin:${PATH}
Install an Older Version
- hosts: servers
roles:
- role: arolfes.graalvm
graalvm_java_version: '17.0.7'
Exclude GraalVM from PATH
To prevent adding GraalVM to your PATH, set graalvm_add_to_path
to false
:
- hosts: servers
roles:
- role: arolfes.graalvm
graalvm_add_to_path: false
Avoid Creating /etc/profile.d/graalvm.sh
File
- hosts: servers
roles:
- role: arolfes.graalvm
graalvm_is_default_installation: false
Install Multiple Versions of GraalVM
You can install multiple versions of GraalVM using this role multiple times:
- hosts: servers
roles:
# This installs graalvm-community-jdk-17.0.7
- role: arolfes.graalvm
graalvm_java_version: '17.0.7'
graalvm_is_default_installation: false
graalvm_fact_group_name: 'graalvm_java_17_0_7'
# This installs graalvm-community-jdk-21.0.2 and it will be the default
- role: arolfes.graalvm
Offline Installation
For offline installation, provide extra information like graalvm_redis_filename
and graalvm_redis_sha256sum
. For example:
# Download `graalvm-community-jdk-21.0.2_linux-x64_bin.tar.gz` to
# `{{ playbook_dir }}/files/` before running this.
- hosts: servers
roles:
- role: arolfes.graalvm
graalvm_java_version: '21.0.2'
graalvm_use_local_archive: true
graalvm_redis_filename: 'graalvm-community-jdk-21.0.2_linux-x64_bin.tar.gz'
graalvm_redis_sha256sum: 'b048069aaa3a99b84f5b957b162cc181a32a4330cbc35402766363c5be76ae48'
Role Facts
This role makes the following Ansible facts available for other roles:
ansible_local.graalvm.general.java_version
(e.g.,21.0.2
)ansible_local.graalvm.general.home
(e.g.,/opt/graalvm/jdk-21.0.2
)
If you change the graalvm_fact_group_name
, the names of the facts will change accordingly.
Development & Testing
This project uses Molecule for development and testing. The role is unit tested with Testinfra and pytest.
To work on or test this role, ensure you have the following installed:
To simplify installation, this project includes Molecule Wrapper, which installs Molecule and its dependencies (except for Linux) and then runs Molecule with the given command.
To test this role using Molecule Wrapper, run:
./moleculew test
Note: Some dependencies may require sudo
permissions to install.
License
MIT License
Credits
A big thanks to John from Gantsign for providing the Molecule wrapper script and for the excellent Ansible roles available on Ansible Galaxy.
Author Information
Alexander Rolfes
Role for installing the graalvm community jdk.
ansible-galaxy install arolfes.graalvm