项目作者: gantsign

项目描述 :
Ansible role for installing Java from AdoptOpenJDK
高级语言: Shell
项目地址: git://github.com/gantsign/ansible-role-java.git
创建时间: 2016-08-13T16:53:28Z
项目社区:https://github.com/gantsign/ansible-role-java

开源协议:MIT License

下载


Ansible Role: Java

Tests
Ansible Galaxy
License

Role to install the Java JDK.

Requirements

  • Ansible Core >= 2.17

  • Linux Distribution

    • Debian Family

      • Debian

        • Bullseye (11)
        • Bookworm (12)
      • Ubuntu

        • Jammy (22.04)
        • Noble (24.04)
    • RedHat Family

      • Rocky Linux

        • 9
      • Fedora

        • 41
    • SUSE Family

      • openSUSE

        • Tumbleweed
    • 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):

  1. # Java version number
  2. # Specify '8', '11', '17', '21' or '24' to get the latest patch version of that
  3. # release.
  4. java_version: '21.0.6+7'
  5. # Base installation directory for any Java distribution
  6. java_install_dir: '/opt/java'
  7. # Directory to store files downloaded for Java installation on the remote box
  8. java_download_dir: "{{ x_ansible_download_dir | default(ansible_env.HOME + '/.ansible/tmp/downloads') }}"
  9. # Location Java installations packages can be found on the local box
  10. # local packages will be uses in preference to downloading new packages.
  11. java_local_archive_dir: '{{ playbook_dir }}/files'
  12. # Wether to use installation packages in the local archive (if available)
  13. java_use_local_archive: true
  14. # If this is the default installation, profile scripts will be written to set
  15. # the JAVA_HOME environment variable and add the bin directory to the PATH
  16. # environment variable.
  17. java_is_default_installation: true
  18. # Name of the group of Ansible facts relating this Java installation.
  19. #
  20. # Override if you want use this role more than once to install multiple versions
  21. # of Java.
  22. #
  23. # e.g. java_fact_group_name: java_8
  24. # would change the Java home fact to:
  25. # ansible_local.java_8.general.home
  26. java_fact_group_name: java
  27. # The SHA-256 for the JDK redistributable
  28. java_redis_sha256sum:
  29. # Mirror location for JDK download (e.g. https://example.com/provisioning/files)
  30. java_redis_mirror:
  31. # File name for the JDK redistributable installation file
  32. java_redis_filename:
  33. # Timeout for JDK download response in seconds
  34. java_download_timeout_seconds: 600
  35. # The timeout for the Adoptium API
  36. java_api_timeout_seconds: 30

Example Playbooks

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:

  1. - hosts: servers
  2. roles:
  3. - role: gantsign.java

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

  1. - hosts: servers
  2. roles:
  3. - role: gantsign.java
  4. java_version: '8.0.442+6'

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

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

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

  1. - hosts: servers
  2. roles:
  3. - role: ansible-role-java
  4. java_version: '8'
  5. java_is_default_installation: false
  6. java_fact_group_name: java_8
  7. - role: ansible-role-java
  8. java_version: '11'
  9. java_is_default_installation: true
  10. 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.26+4:

  1. # Before performing the offline install, download
  2. # `OpenJDK11U-jdk_x64_linux_hotspot_11.0.26_4.tar.gz` to
  3. # `{{ playbook_dir }}/files/` on the local machine.
  4. - hosts: servers
  5. roles:
  6. - role: gantsign.java
  7. java_major_version: '11'
  8. java_version: '11.0.26+4'
  9. java_release_name: 'jdk-11.0.26+4'
  10. java_redis_filename: 'OpenJDK11U-jdk_x64_linux_hotspot_11.0.26_4.tar.gz'
  11. java_redis_sha256sum: '7def4c5807b38ef1a7bb30a86572a795ca604127cc8d1f5b370abf23618104e6'

Role Facts

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

  • ansible_local.java.general.version

    • e.g. 8u442
  • ansible_local.java.general.home

    • e.g. /opt/java/jdk8u442

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

  1. 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 the following tooling:

  • Molecule for orchestrating test scenarios
  • Testinfra for testing the changes on the
    remote
  • pytest the testing framework
  • Tox manages Python virtual
    environments for linting and testing
  • pip-tools for managing dependencies

A Visual Studio Code
Dev Container is
provided for developing and testing this role.

License

MIT

Author Information

John Freeman

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