Puppet Class: elasticsearch::package

Defined in:
manifests/package.pp

Overview

This class exists to coordinate all software package management related actions, functionality and logical units in a central place.

It is not intended to be used directly by external resources like node definitions or other modules.

Examples:

importing this class by other classes to use its functionality:

class { 'elasticsearch::package': }

Author:

  • Richard Pijnenburg <richard.pijnenburg@elasticsearch.com>

  • Tyler Langlois <tyler.langlois@elastic.co>



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

class elasticsearch::package {
  Exec {
    path      => ['/bin', '/usr/bin', '/usr/local/bin'],
    cwd       => '/',
    tries     => 3,
    try_sleep => 10,
  }

  if $elasticsearch::ensure == 'present' {
    if $elasticsearch::restart_package_change {
      Package['elasticsearch'] ~> Class['elasticsearch::service']
    }
    Package['elasticsearch'] ~> Exec['remove_plugin_dir']

    # Create directory to place the package file
    $package_dir = $elasticsearch::package_dir
    exec { 'create_package_dir_elasticsearch':
      cwd     => '/',
      path    => ['/usr/bin', '/bin'],
      command => "mkdir -p ${package_dir}",
      creates => $package_dir,
    }

    file { $package_dir:
      ensure  => 'directory',
      purge   => $elasticsearch::purge_package_dir,
      force   => $elasticsearch::purge_package_dir,
      backup  => false,
      require => Exec['create_package_dir_elasticsearch'],
    }

    # Check if we want to install a specific version or not
    if $elasticsearch::version == false {
      $package_ensure = $elasticsearch::autoupgrade ? {
        true  => 'latest',
        false => 'present',
      }
    } else {
      # install specific version
      $package_ensure = $elasticsearch::pkg_version
    }

    # action
    if ($elasticsearch::package_url != undef) {
      case $elasticsearch::package_provider {
        'package': { $before = Package['elasticsearch'] }
        default:   { fail("software provider \"${elasticsearch::package_provider}\".") }
      }

      $filename_array = split($elasticsearch::package_url, '/')
      $basefilename = $filename_array[-1]

      $source_array = split($elasticsearch::package_url, ':')
      $protocol_type = $source_array[0]

      $ext_array = split($basefilename, '\.')
      $ext = $ext_array[-1]

      $pkg_source = "${package_dir}/${basefilename}"

      case $protocol_type {
        'puppet': {
          file { $pkg_source:
            ensure  => file,
            source  => $elasticsearch::package_url,
            require => File[$package_dir],
            backup  => false,
            before  => $before,
          }
        }
        'ftp', 'https', 'http': {
          if $elasticsearch::proxy_url != undef {
            $exec_environment = [
              'use_proxy=yes',
              "http_proxy=${elasticsearch::proxy_url}",
              "https_proxy=${elasticsearch::proxy_url}",
            ]
          } else {
            $exec_environment = []
          }

          case $elasticsearch::download_tool {
            String: {
              $_download_command = if $elasticsearch::download_tool_verify_certificates {
                $elasticsearch::download_tool
              } else {
                $elasticsearch::download_tool_insecure
              }

              exec { 'download_package_elasticsearch':
                command     => "${_download_command} ${pkg_source} ${elasticsearch::package_url} 2> /dev/null",
                creates     => $pkg_source,
                environment => $exec_environment,
                timeout     => $elasticsearch::package_dl_timeout,
                require     => File[$package_dir],
                before      => $before,
              }
            }
            default: {
              fail("no \$elasticsearch::download_tool defined for ${facts['os']['family']}")
            }
          }
        }
        'file': {
          $source_path = $source_array[1]
          file { $pkg_source:
            ensure  => file,
            source  => $source_path,
            require => File[$package_dir],
            backup  => false,
            before  => $before,
          }
        }
        default: {
          fail("Protocol must be puppet, file, http, https, or ftp. You have given \"${protocol_type}\"")
        }
      }

      if ($elasticsearch::package_provider == 'package') {
        case $ext {
          'deb':   { Package { provider => 'dpkg', source => $pkg_source } }
          'rpm':   { Package { provider => 'rpm', source => $pkg_source } }
          default: { fail("Unknown file extention \"${ext}\".") }
        }
      }
    } else {
      if ($elasticsearch::manage_repo and $facts['os']['family'] == 'Debian') {
        Class['apt::update'] -> Package['elasticsearch']
      }
    }
  } else {
    # Package removal
    if ($facts['os']['family'] == 'Suse') {
      Package {
        provider  => 'rpm',
      }
      $package_ensure = 'absent'
    } else {
      $package_ensure = 'purged'
    }
  }

  if ($elasticsearch::package_provider == 'package') {
    package { 'elasticsearch':
      ensure => $package_ensure,
      name   => $elasticsearch::_package_name,
    }

    exec { 'remove_plugin_dir':
      refreshonly => true,
      command     => "rm -rf ${elasticsearch::real_plugindir}",
    }
  } else {
    fail("\"${elasticsearch::package_provider}\" is not supported")
  }
}