1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191
|
# Defined Type java::adoptium
#
# @summary
# Install one or more versions of Adoptium Temurin OpenJDK (former AdoptOpenJDK).
#
# @param ensure
# Install or remove the package.
#
# @param version_major
# Major version which should be installed, e.g. '16' or '17'
#
# @param version_minor
# Minor version which should be installed, e.g. '0'
#
# @param version_patch
# Minor version which should be installed, e.g. '2'
#
# @param version_build
# Build version which should be installed, e.g. '07'
#
# @param proxy_server
# Specify a proxy server, with port number if needed. ie: https://example.com:8080. (passed to archive)
#
# @param proxy_type
# Proxy server type (none|http|https|ftp). (passed to archive)
#
# @param url
# Full URL
#
# @param basedir
# Directory under which the installation will occur. If not set, defaults to
# /usr/lib/jvm for Debian and /usr/java for RedHat.
#
# @param manage_basedir
# Whether to manage the basedir directory. Defaults to false.
# Note: /usr/lib/jvm is managed for Debian by default, separate from this parameter.
#
# @param manage_symlink
# Whether to manage a symlink that points to the installation directory. Defaults to false.
#
# @param symlink_name
# The name for the optional symlink in the installation directory.
#
define java::adoptium (
Enum['present'] $ensure = 'present',
Optional[String] $version_major = undef,
Optional[String] $version_minor = undef,
Optional[String] $version_patch = undef,
Optional[String] $version_build = undef,
Optional[String] $proxy_server = undef,
Optional[Enum['none', 'http', 'https', 'ftp']] $proxy_type = undef,
Optional[String] $url = undef,
Optional[String] $basedir = undef,
Boolean $manage_basedir = true,
Boolean $manage_symlink = false,
Optional[String] $symlink_name = undef,
) {
# archive module is used to download the java package
include archive
$install_path = "jdk-${version_major}.${version_minor}.${version_patch}+${version_build}"
# determine package type (exe/tar/rpm), destination directory based on OS
case $facts['kernel'] {
'Linux' : {
case $facts['os']['family'] {
'RedHat', 'Amazon' : {
if $basedir {
$_basedir = $basedir
} else {
$_basedir = '/usr/java'
}
}
'Debian' : {
if $basedir {
$_basedir = $basedir
} else {
$_basedir = '/usr/lib/jvm'
}
}
default : {
fail ("unsupported platform ${$facts['os']['name']}")
}
}
$creates_path = "${_basedir}/${install_path}"
$os = 'linux_hotspot'
}
default : {
fail ( "unsupported platform ${$facts['kernel']}" )
}
}
# set java architecture nomenclature
$os_architecture = $facts['os']['architecture'] ? {
default => $facts['os']['architecture']
}
case $os_architecture {
'i386' : { $arch = 'x86-32' }
'x86_64' : { $arch = 'x64' }
'amd64' : { $arch = 'x64' }
default : {
fail ("unsupported platform ${$os_architecture}")
}
}
# package name and path for download from github
#
# following are build based on this real life example full URLs:
#
# https://github.com/adoptium/temurin17-binaries/releases/download/jdk-17.0.1%2B12/OpenJDK17U-jdk_x64_linux_hotspot_17.0.1_12.tar.gz
# https://github.com/adoptium/temurin16-binaries/releases/download/jdk-16.0.2%2B7/OpenJDK16U-jdk_x64_alpine-linux_hotspot_16.0.2_7.tar.gz
$package_name = "OpenJDK${version_major}U-jdk_${arch}_${os}_${version_major}.${version_minor}.${version_patch}_${version_build}.tar.gz"
# if complete URL is provided, use this value for source in archive resource
if $url {
$source = $url
}
else {
$source = "https://github.com/adoptium/temurin${version_major}-binaries/releases/download/jdk-${version_major}.${version_minor}.${version_patch}%2B${version_build}/${package_name}"
notice ("Default source url : ${source}")
}
# full path to the installer
$destination = "/tmp/${package_name}"
notice ("Destination is ${destination}")
case $ensure {
'present' : {
archive { $destination :
ensure => present,
source => $source,
extract_path => '/tmp',
cleanup => false,
creates => $creates_path,
proxy_server => $proxy_server,
proxy_type => $proxy_type,
}
case $facts['kernel'] {
'Linux' : {
case $facts['os']['family'] {
'Debian' : {
ensure_resource('file', $_basedir, {
ensure => directory,
}
)
$install_requires = [Archive[$destination], File[$_basedir]]
}
default : {
$install_requires = [Archive[$destination]]
}
}
if $manage_basedir {
if (!defined(File[$_basedir])) {
file { $_basedir:
ensure => 'directory',
before => Exec["Install Adoptium Temurin java ${version_major} ${version_minor} ${version_patch} ${version_build}"],
}
}
}
$install_adoptium = ['tar', '-zxf', $destination, '-C', $_basedir]
exec { "Install Adoptium Temurin java ${version_major} ${version_minor} ${version_patch} ${version_build}" :
path => '/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin',
command => $install_adoptium,
creates => $creates_path,
require => $install_requires,
}
if ($manage_symlink and $symlink_name) {
file { "${_basedir}/${symlink_name}":
ensure => link,
target => $creates_path,
require => Exec["Install Adoptium Temurin java ${version_major} ${version_minor} ${version_patch} ${version_build}"],
}
}
}
default : {
fail ("unsupported platform ${$facts['kernel']}")
}
}
}
default : {
notice ("Action ${ensure} not supported.")
}
}
}
|