Defined Type: java::download

Defined in:
manifests/download.pp

Summary

Installs Java from a url location.

Overview

Defined Type java::download

Parameters:

  • ensure (Enum['present']) (defaults to: 'present')

    Install or remove the package.

  • version (String[1]) (defaults to: '8')

    Version of Java to install, e.g. ‘7’ or ‘8’. Default values for major and minor versions will be used.

  • version_major (Optional[String]) (defaults to: undef)

    Major version which should be installed, e.g. ‘8u101’. Must be used together with version_minor.

  • version_minor (Optional[String]) (defaults to: undef)

    Minor version which should be installed, e.g. ‘b12’. Must be used together with version_major.

  • java_se (String[1]) (defaults to: 'jdk')

    Type of Java Standard Edition to install, jdk or jre.

  • proxy_server (Optional[String]) (defaults to: undef)

    Specify a proxy server, with port number if needed. ie: example.com:8080. (passed to archive)

  • proxy_type (Optional[Enum['none', 'http', 'https', 'ftp']]) (defaults to: undef)

    Proxy server type (none|http|https|ftp). (passed to archive)

  • url (Optional[String]) (defaults to: undef)

    Full URL

  • jce (Boolean) (defaults to: false)

    Install Oracles Java Cryptographic Extensions into the JRE or JDK

  • jce_url (Optional[String]) (defaults to: undef)

    Full URL to the jce zip file

  • basedir (Optional[String]) (defaults to: undef)

    Directory under which the installation will occur. If not set, defaults to /usr/lib/jvm for Debian and /usr/java for RedHat.

  • manage_basedir (Boolean) (defaults to: false)

    Whether to manage the basedir directory. Defaults to false. Note: /usr/lib/jvm is managed for Debian by default, separate from this parameter.

  • package_type (Optional[String]) (defaults to: undef)

    Type of installation package for specified version of java_se. java_se 6 comes in a few installation package flavors and we need to account for them. Optional forced package types: rpm, rpmbin, tar.gz

  • manage_symlink (Boolean) (defaults to: false)

    Whether to manage a symlink that points to the installation directory. Defaults to false.

  • symlink_name (Optional[String]) (defaults to: undef)

    The name for the optional symlink in the installation directory.



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
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
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
# File 'manifests/download.pp', line 56

define java::download (
  Enum['present']                                 $ensure         = 'present',
  String[1]                                       $version        = '8',
  Optional[String]                                $version_major  = undef,
  Optional[String]                                $version_minor  = undef,
  String[1]                                       $java_se        = 'jdk',
  Optional[String]                                $proxy_server   = undef,
  Optional[Enum['none', 'http', 'https', 'ftp']]  $proxy_type     = undef,
  Optional[String]                                $url            = undef,
  Boolean                                         $jce            = false,
  Optional[String]                                $jce_url        = undef,
  Optional[String]                                $basedir        = undef,
  Boolean                                         $manage_basedir = false,
  Optional[String]                                $package_type   = undef,
  Boolean                                         $manage_symlink = false,
  Optional[String]                                $symlink_name   = undef,
) {
  # archive module is used to download the java package
  include archive

  # validate java Standard Edition to download
  if $java_se !~ /(jre|jdk)/ {
    fail('Java SE must be either jre or jdk.')
  }

  if $jce {
    if $jce_url {
      $jce_download = $jce_url
    } else {
      fail('JCE URL must be specified')
    }
  }

  # determine Java major and minor version, and installation path
  if $version_major and $version_minor {
    $label         = $version_major
    $release_major = $version_major
    $release_minor = $version_minor

    if $release_major =~ /(\d+)u(\d+)/ {
      # Required for CentOS systems where Java8 update number is >= 171 to ensure
      # the package is visible to Puppet. This is only true for installations that
      # don't use the tar.gz package type.
      if $facts['os']['family'] == 'RedHat' and Numeric($2) >= 171 and $package_type != 'tar.gz' {
        $install_path = "${java_se}1.${1}.0_${2}-amd64"
      } else {
        $install_path = "${java_se}1.${1}.0_${2}"
      }
    } else {
      $install_path = "${java_se}${release_major}${release_minor}"
    }
  } else {
    # use default versions if no specific major and minor version parameters are provided
    $label = $version
    case $version {
      '6' : {
        $release_major = '6u45'
        $release_minor = 'b06'
        $install_path = "${java_se}1.6.0_45"
      }
      '7' : {
        $release_major = '7u80'
        $release_minor = 'b15'
        $install_path = "${java_se}1.7.0_80"
      }
      '8' : {
        $release_major = '8u201'
        $release_minor = 'b09'
        $install_path = "${java_se}1.8.0_201"
      }
      default : {
        $release_major = '8u201'
        $release_minor = 'b09'
        $install_path = "${java_se}1.8.0_201"
      }
    }
  }

  # determine package type (exe/tar/rpm), destination directory based on OS
  case $facts['kernel'] {
    'Linux' : {
      case $facts['os']['family'] {
        'RedHat', 'Amazon' : {
          # Oracle Java 6 comes in a special rpmbin format
          if $package_type {
            $_package_type = $package_type
          } elsif $version == '6' {
            $_package_type = 'rpmbin'
          } else {
            $_package_type = 'rpm'
          }
          if $basedir {
            $_basedir = $basedir
          } else {
            $_basedir = '/usr/java'
          }
        }
        'Debian' : {
          if $package_type {
            $_package_type = $package_type
          } else {
            $_package_type = 'tar.gz'
          }
          if $basedir {
            $_basedir = $basedir
          } else {
            $_basedir = '/usr/lib/jvm'
          }
        }
        default : {
          fail ("unsupported platform ${$facts['os']['name']}")
        }
      }

      $creates_path = "${_basedir}/${install_path}"
      $os = 'linux'
      $destination_dir = '/tmp/'
    }
    default : {
      fail ( "unsupported platform ${$facts['kernel']}" )
    }
  }

  # Install required unzip packages for jce
  if $jce {
    ensure_resource('package', 'unzip', { 'ensure' => 'present' })
  }

  # set java architecture nomenclature
  $os_architecture = $facts['os']['architecture'] ? {
    undef => $facts['os']['architecture'],
    default => $facts['os']['architecture']
  }

  case $os_architecture {
    'i386' : { $arch = 'i586' }
    'x86_64' : { $arch = 'x64' }
    'amd64' : { $arch = 'x64' }
    'aarch64' : { $arch = 'aarch64' }
    'arm64' : { $arch = 'aarch64' }
    default : {
      fail ("unsupported platform ${$os_architecture}")
    }
  }

  # following are based on this example:
  # http://download.oracle.com/otn-pub/java/jdk/7u80-b15/jre-7u80-linux-i586.rpm
  #
  # JaveSE 6 distributed in .bin format
  # http://download.oracle.com/otn-pub/java/jdk/6u45-b06/jdk-6u45-linux-i586-rpm.bin
  # http://download.oracle.com/otn-pub/java/jdk/6u45-b06/jdk-6u45-linux-i586.bin
  # package name to use in destination directory for the installer
  case $_package_type {
    'bin' : {
      $package_name = "${java_se}-${version}-${release_major}-${release_minor}-${os}-${arch}.bin"
    }
    'rpmbin' : {
      $package_name = "${java_se}-${version}-${release_major}-${release_minor}-${os}-${arch}-rpm.bin"
    }
    'rpm' : {
      $package_name = "${java_se}-${version}-${release_major}-${release_minor}-${os}-${arch}.rpm"
    }
    'tar.gz' : {
      $package_name = "${java_se}-${version}-${release_major}-${release_minor}-${os}-${arch}.tar.gz"
    }
    default : {
      $package_name = "${java_se}-${version}-${release_major}-${release_minor}-${os}-${arch}.rpm"
    }
  }

  # if complete URL is provided, use this value for source in archive resource
  if $url {
    $source = $url
  }
  else {
    fail('Url must be specified')
  }

  # full path to the installer
  $destination = "${destination_dir}${package_name}"
  notice ("Destination is ${destination}")

  case $_package_type {
    'bin' : {
      $install_command = ['sh', $destination]
    }
    'rpmbin' : {
      $install_command = ['sh', $destination, '-x;', 'rpm', '--force', '-iv', 'sun*.rpm;', 'rpm', '--force', '-iv', "${java_se}*.rpm"]
    }
    'rpm' : {
      $install_command = ['rpm', '--force', '-iv', $destination]
    }
    'tar.gz' : {
      $install_command = ['tar', '-zxf', $destination, '-C', $_basedir]
    }
    default : {
      $install_command = ['rpm', '-iv', $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 {
            ensure_resource('file', $_basedir, { 'ensure' => 'directory', 'before' => Exec["Install Oracle java_se ${java_se} ${version} ${release_major} ${release_minor}"] })
          }

          exec { "Install Oracle java_se ${java_se} ${version} ${release_major} ${release_minor}" :
            path    => '/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin',
            command => $install_command,
            creates => $creates_path,
            require => $install_requires,
          }

          if ($manage_symlink and $symlink_name) {
            file { "${_basedir}/${symlink_name}":
              ensure  => link,
              target  => $creates_path,
              require => Exec["Install Oracle java_se ${java_se} ${version} ${release_major} ${release_minor}"],
            }
          }

          if ($jce and $jce_download != undef) {
            $jce_path = $java_se ? {
              'jre' => "${creates_path}/lib/security",
              'jdk' => "${creates_path}/jre/lib/security"
            }
            archive { "/tmp/jce-${version}.zip":
              source        => $jce_download,
              extract       => true,
              extract_path  => $jce_path,
              extract_flags => '-oj',
              creates       => "${jce_path}/US_export_policy.jar",
              cleanup       => false,
              proxy_server  => $proxy_server,
              proxy_type    => $proxy_type,
              require       => [
                Package['unzip'],
                Exec["Install Oracle java_se ${java_se} ${version} ${release_major} ${release_minor}"]
              ],
            }
          }
        }
        default : {
          fail ("unsupported platform ${$facts['kernel']}")
        }
      }
    }
    default : {
      notice ("Action ${ensure} not supported.")
    }
  }
}