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.

Examples:

Install a plugin.

logstash::plugin { 'logstash-input-stdin': }

Remove a plugin.

logstash::plugin { 'logstash-input-stout':
  ensure => absent,
}

Install a plugin from a local file.

logstash::plugin { 'logstash-input-custom':
  source => 'file:///tmp/logstash-input-custom.gem',
}

Install a plugin from a Puppet module.

logstash::plugin { 'logstash-input-custom':
  source => 'puppet:///modules/logstash-site-plugins/logstash-input-custom.gem',
}

Install X-Pack.

logstash::plugin { 'x-pack':
  source => 'https://artifacts.elastic.co/downloads/packs/x-pack/x-pack-5.3.0.zip',
}

Install a plugin, overriding JVM options via the environment.

logstash::plugin { 'logstash-input-jmx':
  environment => ['LS_JAVA_OPTS=-Xms1g -Xmx1g']
}

Parameters:

  • ensure (String) (defaults to: present)

    Install or remove with ‘present` or `absent`.

  • source (String) (defaults to: undef)

    Install from this file, not from RubyGems.

  • user (String) (defaults to: 'root')

    User to install plugin as.

  • environment (String) (defaults to: [])

    Environment used when running ‘logstash-plugin’



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/plugin.pp', line 42

define logstash::plugin (
  $source = undef,
  $ensure = present,
  $environment = [],
  String $user = 'root',
) {
  require logstash::package
  $exe = "${logstash::home_dir}/bin/logstash-plugin"

  Exec {
    path        => '/bin:/usr/bin',
    cwd         => '/tmp',
    user        => $user,
    timeout     => 1800,
    environment => $environment,
  }

  case $source { # Where should we get the plugin from?
    undef: {
      # No explict source, so search Rubygems for the plugin, by name.
      # ie. "logstash-plugin install logstash-output-elasticsearch"
      $plugin = $name
    }

    /^(\/|file:)/: {
      # A gem file that is already available on the local filesystem.
      # Install from the local path.
      # ie. "logstash-plugin install /tmp/logtash-filter-custom.gem" or
      # "logstash-plugin install file:///tmp/logtash-filter-custom.gem" or
      $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}"],
      }

      case $source {
        /\.zip$/: {
          $plugin = "file://${downloaded_file}"
        }
        default: {
          $plugin = $downloaded_file
        }
      }
    }

    /^https?:/: {
      # An 'http(s):///' URL.
      $plugin = $source
    }

    default: {
      fail('"source" should be a local path, a "puppet:///" url, or undef.')
    }
  }

  case $ensure {
    'present': {
      exec { "install-${name}":
        command => "${exe} install ${plugin}",
        unless  => "${exe} list ^${name}$",
      }
    }

    /^\d+\.\d+\.\d+/: {
      exec { "install-${name}":
        command => "${exe} install --version ${ensure} ${plugin}",
        unless  => "${exe} list --verbose ^${name}$ | grep --fixed-strings --quiet '(${ensure})'",
      }
    }

    'absent': {
      exec { "remove-${name}":
        command => "${exe} remove ${name}",
        onlyif  => "${exe} list | grep -q ^${name}$",
      }
    }

    default: {
      fail "'ensure' should be 'present', 'absent', or a version like '1.3.4'."
    }
  }
}