Puppet Class: oracle_java

Defined in:
manifests/init.pp

Overview

Class: oracle_java

This module installs Oracle Java from official RPM packages

Parameters:

version

Java SE version to install (valid format: ‘major’u’minor’ or just ‘major’)

build

build number associated to the requested Java SE version (valid format: ‘-b###’)

type

envionment type to install (valid: ‘jre’|‘jdk’)

format

archive format (valid: ‘rpm’|‘tar.gz’)

ssousername

user name of oracle.com account

ssopassword

password of oracle.com account

install_path

defines the root path where the Java archives are extracted. Requires ‘tar.gz’ format

check_checksum

enable checksum validation on downloaded archives (boolean)

checksum

use a custom checksum to verify the archive integrity

add_alternative

add java alternative (boolean)

add_system_env

add system-wide Java environment variables (boolean)

download_url

base url of a custom location to fetch the installation package from

filename

custom file name to use when downloading the installation package

proxy_server

proxy server url

proxy_type

proxy server type (valid: ‘none’|‘http’|‘https’|‘ftp’)

urlcode

complex code oracle started adding to the ‘download_url’ starting from java 8u121

Actions:

  • Install Oracle jre/jdk

Requires:

  • puppetlabs/stdlib module

  • puppet/archive module

Sample Usage:

class { 'oracle_java':
  version         => '8u5',
  type            => 'jdk',
  format          => 'rpm',
  add_alternative => true
}

Parameters:

  • version (Any) (defaults to: '8')
  • build (Any) (defaults to: undef)
  • type (Any) (defaults to: 'jre')
  • format (Any) (defaults to: undef)
  • ssousername (Any) (defaults to: undef)
  • ssopassword (Any) (defaults to: undef)
  • check_checksum (Any) (defaults to: true)
  • checksum (Any) (defaults to: undef)
  • add_alternative (Any) (defaults to: false)
  • add_system_env (Any) (defaults to: false)
  • install_path (Any) (defaults to: '/usr/java')
  • download_url (Any) (defaults to: undef)
  • filename (Any) (defaults to: undef)
  • proxy_server (Any) (defaults to: undef)
  • proxy_type (Any) (defaults to: undef)
  • urlcode (Any) (defaults to: undef)


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
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
# File 'manifests/init.pp', line 58

class oracle_java (
  $version         = '8',
  $build           = undef,
  $type            = 'jre',
  $format          = undef,
  $ssousername     = undef,
  $ssopassword     = undef,
  $check_checksum  = true,
  $checksum        = undef,
  $add_alternative = false,
  $add_system_env  = false,
  $install_path    = '/usr/java',
  $download_url    = undef,
  $filename        = undef,
  $proxy_server    = undef,
  $proxy_type      = undef,
  $urlcode         = undef) {
  if !$format {
    if $::osfamily =~ /RedHat|Suse/ or $::operatingsystem == 'Mageia' {
      case $install_path {
        '/usr/java' : { $format_real = 'rpm' }
        default     : {
          notice("'install_path' set to custom location on RPM platform, falling back to tar.gz installation")
          $format_real = 'tar.gz'
        }
      }
    } else {
      $format_real = 'tar.gz'
    }
  } else {
    $format_real = $format
  }

  # parameters validation
  if $version !~ /^([6-9]|[6-9]u[0-9]{1,3}|9\.[0-9]{1}\.[0-9]{1,3})$/ {
    fail('$version must be formated as \'major\', \'major\'u\'minor\' or \'major\'.\'minor\'.\'patch\' (Java 9)')
  }
  if $type !~ /^(jre|jdk)$/ {
    fail('$type must be either \'jre\' or \'jdk\'')
  }
  if $format_real !~ /^(rpm|tar\.gz)$/ {
    fail('$format must be either \'rpm\' or \'tar.gz\'')
  }

  # set to latest release if no minor version was provided
  if $version == '9' {
    $version_real = '9.0.4'
  } elsif $version == '8' {
    $version_real = '8u172'
  } elsif $version == '7' {
    $version_real = '7u80'
  } elsif $version == '6' {
    $version_real = '6u45'
  } else {
    $version_real = $version
  }

  # translate system architecture to expected value
  case $::architecture {
    /x86_64|amd64/ : { $arch = 'x64' }
    'x86'          : { $arch = 'i586' }
    default        : { fail("oracle_java does not support architecture ${::architecture} (yet)") }
  }

  # get major/minor version numbers
  if versioncmp($version_real, '9') >= 0 {
    $array_version = split($version_real, '\.')
    $maj_version = $array_version[0]
    $min_version = $array_version[2]
  } else {
    $array_version = split($version_real, 'u')
    $maj_version = $array_version[0]
    $min_version = $array_version[1]
  }

  # remove extra particle if minor version is 0
  $version_final = delete($version_real, 'u0')
  if versioncmp($version_final, '9') >= 0 {
    $longversion = "${type}-${version_final}"
  } else {
    $longversion = $min_version ? {
      '0'       => "${type}1.${maj_version}.0",
      /^[0-9]$/ => "${type}1.${maj_version}.0_0${min_version}",
      default   => "${type}1.${maj_version}.0_${min_version}"
    }
  }

  # define installer filename
  if !$filename {
    case $maj_version {
      '6'     : {
        case $format_real {
          'rpm'   : { $filename_real = "${type}-${version_final}-linux-${arch}-rpm.bin" }
          default : { $filename_real = "${type}-${version_final}-linux-${arch}.bin" }
        }
      }
      '9'     : { $filename_real = "${type}-${version_final}_linux-${arch}_bin.${format_real}" }
      default : { $filename_real = "${type}-${version_final}-linux-${arch}.${format_real}" }
    }
  } else {
    $filename_real = $filename
  }

  # used for installing Java 6 RPM only
  # determine filename once .bin is extracted
  if $maj_version == '6' and $format_real == 'rpm' {
    case $arch {
      'x64'   : { $filename_extracted = "${type}-${version_final}-linux-amd64.rpm" }
      default : { $filename_extracted = "${type}-${version_final}-linux-${arch}.rpm" }
    }
  }

  # define build number and url code
  if !$build {
    contain oracle_java::javalist # get build numbers, url codes
    $build_real = $oracle_java::javalist::buildnumber
    $urlcode_real = $oracle_java::javalist::urlcode
  } else {
    $build_real = $build
    $urlcode_real = $urlcode
  }

  # define checksum
  if $check_checksum {
    if !$checksum {
      contain oracle_java::checksums # get checksums list
      $checksum_real = $oracle_java::checksums::md5checksum
    } else {
      $checksum_real = $checksum
    }
  }

  # define download URL
  if !$download_url {
    $download_url_real = "http://download.oracle.com/otn-pub/java/jdk/${version_final}${build_real}${urlcode_real}"
    $oracle_url = true
  } else {
    $download_url_real = $download_url
    $oracle_url = false
  }

  # define package name
  if versioncmp($version_final, '8u151') >= 0 and $maj_version != '9' {
    $packagename = "${type}1.${maj_version}"
  } elsif versioncmp($version_final, '8u20') >= 0 {
    $packagename = $longversion
  } else {
    $packagename = $type
  }

  # annnnd... let's go
  contain oracle_java::download
  contain oracle_java::install
  Class['oracle_java::download'] ~> Class['oracle_java::install']

  if $add_alternative {
    contain oracle_java::alternative
    Class['oracle_java::install'] -> Class['oracle_java::alternative']
  }

  if $add_system_env {
    contain oracle_java::env
  }
}