Puppet Class: virtualbox::install

Defined in:
manifests/install.pp

Summary

installs the VirtualBox package

Overview

This is a private class meant to be called from virtualbox This class installs the VirtualBox package. Based on the parameters it will also install a package repository.

Parameters:

  • version (String) (defaults to: $virtualbox::version)

    The major version of the package to install.

  • package_ensure (String) (defaults to: $virtualbox::package_ensure)

    This gets passed to the package resource as the value of the ‘ensure’ parameter. This can be used to specify a package version.

  • package_name (String) (defaults to: $virtualbox::package_name)

    The name of the package to install. This must be the full packge name when not the default. When the default is in use, it gets compounded with the major.minor components of the version number.

  • manage_repo (Boolean) (defaults to: $virtualbox::manage_repo)

    Should this module manage the package repository?

  • repo_proxy (Optional[String]) (defaults to: $virtualbox::repo_proxy)

    proxy used by yum

  • manage_package (Boolean) (defaults to: $virtualbox::manage_package)

    Should this module manage the package?



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
# File 'manifests/install.pp', line 21

class virtualbox::install (
  String $version               = $virtualbox::version,
  String $package_ensure        = $virtualbox::package_ensure,
  String $package_name          = $virtualbox::package_name,
  Boolean $manage_repo          = $virtualbox::manage_repo,
  Optional[String] $repo_proxy  = $virtualbox::repo_proxy,
  Boolean $manage_package       = $virtualbox::manage_package
) {
  if $package_name == $virtualbox::params::package_name {
    $validated_package_name = "${package_name}-${version}"
  } else {
    $validated_package_name = $package_name
  }

  case $facts['os']['family'] {
    'Debian': {
      if $manage_repo {
        include apt

        if $repo_proxy {
          warning('The $repo_proxy parameter is not implemented on Debian-like systems. Please use the $proxy parameter on the apt class. Ignoring.')
        }

        apt::source { 'virtualbox':
          architecture => $facts['os']['architecture'],
          location     => 'https://download.virtualbox.org/virtualbox/debian',
          repos        => 'contrib',
          key          => {
            'id'     => 'B9F8D658297AF3EFC18D5CDFA2F683C52980AECF',
            'source' => 'https://www.virtualbox.org/download/oracle_vbox_2016.asc',
          },
        }

        if $manage_package {
          Apt::Source['virtualbox'] -> Class['apt::update'] -> Package['virtualbox']
        }
      }
    }
    'RedHat': {
      if $manage_repo {
        $platform = $facts['os']['name'] ? {
          'Fedora' => 'fedora',
          default  => 'el',
        }

        yumrepo { 'virtualbox':
          descr    => 'Oracle Linux / RHEL / CentOS-$releasever / $basearch - VirtualBox',
          baseurl  => "https://download.virtualbox.org/virtualbox/rpm/${platform}/\$releasever/\$basearch",
          gpgkey   => 'https://www.virtualbox.org/download/oracle_vbox.asc',
          gpgcheck => 1,
          enabled  => 1,
          proxy    => $repo_proxy,
        }

        if $manage_package {
          Yumrepo['virtualbox'] -> Package['virtualbox']
        }
      }
    }
    'Suse': {
      case $facts['os']['name'] {
        'OpenSuSE': {
          if $manage_repo {
            if $facts['os']['release']['full'] !~ /^(12.3|11)/ {
              fail('Oracle only supports OpenSuSE 11 and 12.3! You need to manage your own repo.')
            }

            zypprepo { 'virtualbox':
              baseurl     => "https://download.virtualbox.org/virtualbox/rpm/opensuse/${facts['os']['release']['full']}",
              enabled     => 1,
              autorefresh => 1,
              name        => 'Oracle Virtual Box',
              gpgcheck    => 0,
            }
            if $manage_package {
              Zypprepo['virtualbox'] -> Package['virtualbox']
            }
          }
        }
        default: { fail("${facts['os']['family']}/${facts['os']['name']} is not supported.") }
      }
    }
    default: { fail("${facts['os']['family']} is not supported.") }
  }

  if $manage_package {
    $_install_status = $facts['virtualbox_version'] ? {
      Pattern["^${version}"] => 'already-installed',
      Pattern['^5']          => 'upgrade',
      default                => 'not-yet-installed',
    }

    if $_install_status == 'upgrade' {
      # The version returned by fact is complete, like 5.2.27r129424.
      # Bellow, we try to match only the firsts two digits, like 5.2.
      $_current_version = $facts['virtualbox_version'].match(/^[0-9][^0-9]{1}[0-9]{1}/)

      package { "${package_name}-${_current_version[0]}":
        ensure => absent,
      }

      Package["${package_name}-${_current_version[0]}"] -> Package['virtualbox']
    }
    package { 'virtualbox':
      ensure => $package_ensure,
      name   => $validated_package_name,
    }
  }
}