Defined Type: logstash::plugin
- Defined in:
- manifests/plugin.pp
Overview
Manage the installation of a Logstash plugin.
By default, plugins are downloaded from RubyGems, but it is also possible to install from a local Gem, or one stored in Puppet.
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 |
# File 'manifests/plugin.pp', line 26
define logstash::plugin (
$source = undef,
$ensure = present,
)
{
require logstash::package
$exe = '/opt/logstash/bin/plugin'
# Install plugin as logstash user and make
# sure we find su on centos and debian
Exec {
path => '/bin:/usr/bin',
}
$exe_prefix = "su - '${::logstash::logstash_user}' -s /bin/bash -c '"
$exe_suffix = "'"
case $source { # Where should we get the plugin from?
undef: {
# No explict source, so search Rubygems for the plugin, by name.
# ie. "/opt/logstash/bin/plugin install logstash-output-elasticsearch"
$plugin = $name
}
/^\//: {
# A gem file that is already available on the local filesystem.
# Install from the local path.
# ie. "/opt/logstash/bin/plugin install /tmp/logtash-filter-custom.gem"
$plugin = $source
}
/^puppet:/: {
# A 'puppet:///' URL. Download the gem from Puppet, then install
# the plugin from the downloaded file.
$downloaded_file = sprintf('/tmp/%s', basename($source))
file { $downloaded_file:
source => $source,
before => Exec["install-${name}"],
}
$plugin = $downloaded_file
}
default: {
fail('"source" should be a local path, a "puppet:///" url, or undef.')
}
}
case $ensure {
'present': {
exec { "install-${name}":
command => "${exe_prefix}${exe} install ${plugin}${exe_suffix}",
unless => "${exe_prefix}${exe} list ^${name}${exe_suffix}$",
timeout => 1800,
}
}
/^\d+\.\d+\.\d+/: {
exec { "install-${name}":
command => "${exe_prefix}${exe} install --version ${ensure} ${plugin}${exe_suffix}",
unless => "${exe_prefix}${exe} list --verbose ^${name}\$${exe_suffix} | grep --fixed-strings --quiet '(${ensure})'",
timeout => 1800,
}
}
'absent': {
exec { "remove-${name}":
command => "${exe_prefix}${exe} uninstall ${name}${exe_suffix}",
onlyif => "${exe_prefix}${exe} list${exe_suffix} | grep -q ^${name}$",
timeout => 1800,
}
}
default: {
fail "'ensure' should be 'present' or 'absent'."
}
}
}
|