项目作者: frieder

项目描述 :
An Ansible role to install Oracle JDK 8/9 on several Linux OS.
高级语言:
项目地址: git://github.com/frieder/ansible-role-oraclejdk.git
创建时间: 2017-09-28T19:24:49Z
项目社区:https://github.com/frieder/ansible-role-oraclejdk

开源协议:MIT License

下载


ansible-role-oraclejdk

An Ansible role to install Oracle JDK.

Platform
Platform
Platform
Platform
Platform
Platform
Platform

OracleJDK
OracleJDK

Summary

This Ansible role installs Oracle JDK and Java Cryptography Extension (optional) on the target host. OpenJDK is not supported. It has been tested with Oracle JDK 8u144/8u151 and JDK 9u181/9.0.1 on the following Linux distributions.

  • Ubuntu 16.04
  • Debian 9
  • RHEL 7.4
  • CentOS 7.3
  • Fedora 26
  • SLE 12 SP2
  • openSUSE 42.2

Dependencies

Ansible >= 2.x (tested with 2.3.2.0 and 2.4.0.0)

In addition this role requires the following packages to be installed on the target host.

  • tar - Always required to extract the JDK tar.gz archive
  • unzip - Only required if JCE for JDK8 should be installed

Installation

To use this role it must first get downloaded from Ansible Galaxy. To install the role execute the command below on your Ansible controle machine. For more information please refer to the official documentation.

ansible-galaxy install frieder.oraclejdk

The command above will always pull the latest version off of Galaxy. Another possibility is to pull the role from Github and define a specific release version to download. This allows for better control over which version of this role to be used. Create a requirements.yml and put the following content in it.

  1. ---
  2. - name: frieder.oraclejdk
  3. src: https://github.com/frieder/ansible-role-oraclejdk
  4. version: 2.0.0

Next you can execute ansible-galaxy install -r ./requirements.yml --ignore-errors and it will download all dependencies defined in this list. --ignore-errors will make sure that the whole list is processed even when some dependencies are already downloaded. A nice overview of possible entries for requirements.yml can be found here.

Role Variables

All role variables are defined in defaults/main.yml. One can overwrite these values in the playbook (see examples at the bottom).

Variable Default Description
oraclejdk_license_accept false When installing a JDK this must be set to true otherwise the play will fail. Not required when removing a JDK.
oraclejdk_state present Defines whether to add or remove a JDK from the target host. Possible values are [present,absent].
oraclejdk_cleanup true Remove all temp files/folders (both local and remote) after installation. When set to true this will result in “changed” plays.
oraclejdk_dl_dir /tmp/oraclejdk The folder (both local and remote) to which the archives get downloaded/copied/extracted.
oraclejdk_home Depending on the value of oraclejdk_state this property takes different values. In case of present it will take a single string pointing to the desired location of JAVA_HOME. In case of absent it takes a list of former JDK locations that should now be removed. In this case provide a list with at least one entry.
oraclejdk_profile_file /etc/profile.d/java.sh The file in which the role will set the JAVA_HOME and PATH export.
oraclejdk_cookie Cookie:oraclelicense=accept-securebackup-cookie The cookie required for automated downloads from oracle.com. License check is done with a different variable.
oraclejdk_url The URL of the JDK archive either at oracle.com or a local corporate repository (recommended).
oraclejdk_url_user In case that simple HTTP auth is required one can provide a username here.
oraclejdk_url_pass In case that simple HTTP auth is required one can provide a password here.
oraclejdk_checksum The SHA256 checksum of the JDK archive. This is used to verify that the downloaded file is valid. To disable this check just provide an empty checksum value (oraclejdk_checksum: '').
oraclejdk_sethome true When set to true it will update the global variable JAVA_HOME to point to the installation directory of the JDK and add the binaries to the PATH variable. Also have a look at the oraclejdk_profile_file variable.
oraclejdk_alternative_upd true When set to true it will set the alternative for java (update-alternatives --config java) to the current JDK.
oraclejdk_alternative_prio 1 The priority used for the update-alternatives command. The JDK with the highest priority wins.
oraclejdk_alternative_items
  • jar
  • java
  • javac
  • jcmd
  • jconsole
  • jmap
  • jps
  • jstack
  • jstat
  • jstatd
This property allows to define what kind of alternatives should be configured for the JDK.
oraclejdk_jce_install false When set to true it will install and add the latest Java Cryptography Extension (JCE) to the JDK. Please note that with JDK9 the unlimited key strength is enabled by default and no additional action are required. For more information please refer to the security-dev mailinglist.
oraclejdk_jce_name UnlimitedJCEPolicyJDK8 JDK8 only. The name of the folder inside the JCE archive.
oraclejdk_jce_url JDK8 only. The URL of the JCE archive either at oracle.com or a local corporate repository (recommended).
oraclejdk_jce_checksum JDK8 only. The SHA256 checksum of the JCE archive. To disable this check just provide an empty checksum value (oraclejdk_jce_checksum: '').

Example Playbooks

Following are some examples how to use this role in an Ansible playbook.

JDK8 & JDK9 together, set home for JDK8, update alternatives for both JDKs with different priorities

  1. - hosts: jdk
  2. pre_tasks:
  3. - name: Install required packages (127.0.0.1)
  4. delegate_to: 127.0.0.1
  5. run_once: true
  6. package:
  7. name: '{{ item }}'
  8. state: present
  9. with_items:
  10. - tar
  11. - unzip
  12. roles:
  13. - role: frieder.oraclejdk
  14. oraclejdk_license_accept: true
  15. oraclejdk_home: /opt/java/jdk9.0.1
  16. oraclejdk_sethome: false
  17. oraclejdk_alternative_prio: 100
  18. oraclejdk_url: 'http://download.oracle.com/otn-pub/java/jdk/9.0.1+11/jdk-9.0.1_linux-x64_bin.tar.gz'
  19. oraclejdk_checksum: 'sha256:2cdaf0ff92d0829b510edd883a4ac8322c02f2fc1beae95d048b6716076bc014'
  20. - role: frieder.oraclejdk
  21. oraclejdk_license_accept: true
  22. oraclejdk_home: /opt/java/jdk8u151
  23. oraclejdk_alternative_prio: 200
  24. oraclejdk_url: 'http://download.oracle.com/otn-pub/java/jdk/8u151-b12/e758a0de34e24606bca991d704f6dcbf/jdk-8u151-linux-x64.tar.gz'
  25. oraclejdk_checksum: 'sha256:c78200ce409367b296ec39be4427f020e2c585470c4eed01021feada576f027f'
  26. oraclejdk_jce_install: true
  27. oraclejdk_jce_url: 'http://download.oracle.com/otn-pub/java/jce/8/jce_policy-8.zip'
  28. oraclejdk_jce_checksum: 'sha256:f3020a3922efd6626c2fff45695d527f34a8020e938a49292561f18ad1320b59'

JDK8 w/ minimal configuration

  1. - hosts: jdk8
  2. roles:
  3. - role: frieder.oraclejdk
  4. oraclejdk_license_accept: true
  5. oraclejdk_home: /opt/java/jdk8_151
  6. oraclejdk_url: 'http://download.oracle.com/otn-pub/java/jdk/8u151-b12/e758a0de34e24606bca991d704f6dcbf/jdk-8u151-linux-x64.tar.gz'
  7. oraclejdk_checksum: 'sha256:c78200ce409367b296ec39be4427f020e2c585470c4eed01021feada576f027f'

JDK8 w/ JCE

  1. - hosts: jdk8
  2. roles:
  3. - role: frieder.oraclejdk
  4. oraclejdk_license_accept: true
  5. oraclejdk_home: /opt/java/java-8-151
  6. oraclejdk_url: 'http://download.oracle.com/otn-pub/java/jdk/8u151-b12/e758a0de34e24606bca991d704f6dcbf/jdk-8u151-linux-x64.tar.gz'
  7. oraclejdk_checksum: 'sha256:c78200ce409367b296ec39be4427f020e2c585470c4eed01021feada576f027f'
  8. oraclejdk_jce_install: true
  9. oraclejdk_jce_url: 'http://download.oracle.com/otn-pub/java/jce/8/jce_policy-8.zip'
  10. oraclejdk_jce_checksum: 'sha256:f3020a3922efd6626c2fff45695d527f34a8020e938a49292561f18ad1320b59'

JDK8 full config

  1. - hosts: jdk8
  2. roles:
  3. - role: frieder.oraclejdk
  4. oraclejdk_license_accept: true
  5. oraclejdk_cleanup: true
  6. oraclejdk_dl_dir: /tmp/java_download
  7. oraclejdk_home: /opt/java/java-8-151
  8. oraclejdk_sethome: true
  9. oraclejdk_alternative_upd: true
  10. oraclejdk_alternative_prio: 123
  11. oraclejdk_alternative_items:
  12. - jar
  13. - java
  14. - javac
  15. - jcmd
  16. - jconsole
  17. - jmap
  18. - jps
  19. - jstack
  20. - jstat
  21. - jstatd
  22. oraclejdk_profile_file: /etc/profile.d/java.sh
  23. oraclejdk_url: 'http://download.oracle.com/otn-pub/java/jdk/8u151-b12/e758a0de34e24606bca991d704f6dcbf/jdk-8u151-linux-x64.tar.gz'
  24. oraclejdk_checksum: 'sha256:c78200ce409367b296ec39be4427f020e2c585470c4eed01021feada576f027f'
  25. oraclejdk_jce_install: true
  26. oraclejdk_jce_url: 'http://download.oracle.com/otn-pub/java/jce/8/jce_policy-8.zip'
  27. oraclejdk_jce_checksum: 'sha256:f3020a3922efd6626c2fff45695d527f34a8020e938a49292561f18ad1320b59'

JDK9

  1. - hosts: jdk9
  2. roles:
  3. - role: frieder.oraclejdk
  4. oraclejdk_license_accept: true
  5. oraclejdk_home: /opt/java/jdk9.0.1
  6. oraclejdk_url: 'http://download.oracle.com/otn-pub/java/jdk/9.0.1+11/jdk-9.0.1_linux-x64_bin.tar.gz'
  7. oraclejdk_checksum: 'sha256:2cdaf0ff92d0829b510edd883a4ac8322c02f2fc1beae95d048b6716076bc014'

JDK9 w/o checksum check

  1. - hosts: - hosts: jdk9
  2. roles:
  3. - role: frieder.oraclejdk
  4. oraclejdk_license_accept: true
  5. oraclejdk_home: /opt/java/jdk9.0.1
  6. oraclejdk_url: 'http://download.oracle.com/otn-pub/java/jdk/9.0.1+11/jdk-9.0.1_linux-x64_bin.tar.gz'
  7. oraclejdk_checksum: ''

JDK9 add new JDK, remove old JDKs

  1. - hosts: jdk9
  2. roles:
  3. - role: frieder.oraclejdk
  4. oraclejdk_license_accept: true
  5. oraclejdk_home: /opt/java/jdk9.0.1
  6. oraclejdk_url: 'http://download.oracle.com/otn-pub/java/jdk/9.0.1+11/jdk-9.0.1_linux-x64_bin.tar.gz'
  7. oraclejdk_checksum: ''
  8. - role: frieder.oraclejdk
  9. oraclejdk_state: absent
  10. oraclejdk_home:
  11. - /opt/java/jdk9.0.1
  12. - /opt//opt/java/java-8-151