Puppet Class: logstash::package

Defined in:
manifests/package.pp

Overview

This class manages the Logstash package.

It is usually used only by the top-level logstash class. It's unlikely that you will need to declare this class yourself.

Examples:

Include this class to ensure its resources are available.

include logstash::package

Parameters:

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

    The name of the Logstash package in the package manager.

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

    Install precisely this version from the package manager.

  • package_url (String) (defaults to: $logstash::package_url)

    Get the package from this URL, not from the package manager.

Author:



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

class logstash::package(
  $package_url = $logstash::package_url,
  $version = $logstash::version,
  $package_name = $logstash::package_name,
)
{
  Exec {
    path      => [ '/bin', '/usr/bin', '/usr/local/bin' ],
    cwd       => '/',
    tries     => 3,
    try_sleep => 10,
  }

  File {
    ensure => file,
    backup => false,
  }

  if $logstash::ensure == 'present' {
    # Check if we want to install a specific version.
    if $version {
      if $::osfamily == 'redhat' {
        # Prerelease RPM packages have tildes ("~") in their version strings,
        # which can be quite surprising to the user. Let them say:
        #   6.0.0-rc2
        # not:
        #   6.0.0~rc2
        $package_ensure = regsubst($version, '(\d+)-(alpha|beta|rc)(\d+)$', '\1~\2\3')
      }
      else {
        $package_ensure = $version
      }
    }
    else {
      $package_ensure = $logstash::auto_upgrade ? {
        true  => 'latest',
        false => 'present',
      }
    }

    if ($package_url) {
      $filename = basename($package_url)
      $extension = regsubst($filename, '.*\.', '')
      $protocol = regsubst($package_url, ':.*', '')
      $package_local_file = "/tmp/${filename}"

      case $protocol {
        'puppet': {
          file { $package_local_file:
            source => $package_url,
          }
        }
        'ftp', 'https', 'http': {
          exec { "download_package_logstash_${name}":
            command => "wget -O ${package_local_file} ${package_url} 2> /dev/null",
            path    => ['/usr/bin', '/bin'],
            creates => $package_local_file,
            timeout => $logstash::download_timeout,
          }
        }
        'file': {
          file { $package_local_file:
            source => $package_url,
          }
        }
        default: {
          fail("Protocol must be puppet, file, http, https, or ftp. Not '${protocol}'")
        }
      }

      case $extension {
        'deb':   { $package_provider = 'dpkg'  }
        'rpm':   { $package_provider = 'rpm'   }
        default: { fail("Unknown file extension '${extension}'.") }
      }

      $package_require = undef
    }
    else {
      # Use the OS packaging system to locate the package.
      $package_local_file = undef
      $package_provider = undef
      if $::osfamily == 'Debian' {
        $package_require = Class['apt::update']
      } else {
        $package_require = undef
      }
    }
  }
  else { # Package removal
    $package_local_file = undef
    $package_require = undef
    if ($::osfamily == 'Suse') {
      $package_provider = 'rpm'
      $package_ensure = 'absent' # "purged" not supported by provider
    }
    else {
      $package_provider = undef # ie. automatic
      $package_ensure = 'purged'
    }
  }

  package { 'logstash':
    ensure   => $package_ensure,
    name     => $package_name,
    source   => $package_local_file, # undef if using package manager.
    provider => $package_provider, # undef if using package manager.
    require  => $package_require,
  }
}