| Index: modules/elasticsearch/manifests/plugin.pp |
| diff --git a/modules/elasticsearch/manifests/plugin.pp b/modules/elasticsearch/manifests/plugin.pp |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..fde9949bc2c944524c50319afb5534c3dfdf9c12 |
| --- /dev/null |
| +++ b/modules/elasticsearch/manifests/plugin.pp |
| @@ -0,0 +1,69 @@ |
| +# == Type: elasticsearch::plugin |
| +# |
| +# Manage Elasticsearch plugin installations. |
| +# |
| +# === Parameters: |
| +# |
| +# [*ensure*] |
| +# Either 'present'/'installed' or 'absent'/'purged'. |
| +# |
| +# [*replace*] |
| +# Whether to replace an existing plugin during installation. |
| +# |
| +# [*url*] |
| +# Where to download a plugin from during installation, if not publicly |
| +# available at one of the default URLs. |
| +# |
| +# [*version*] |
| +# An explicit version to install. |
| +# |
| +# === Examples: |
| +# |
| +# elasticsearch::plugin {'license': |
| +# url => $elasticsearch_license_plugin_url, |
| +# } |
| +# |
| +# elasticsearch::plugin {'shield': |
| +# require => Elasticsearch::Plugin['license'], |
| +# } |
| +# |
| +define elasticsearch::plugin ( |
| + $ensure = 'present', |
| + $replace = false, |
| + $url = undef, |
| + $version = 'latest', |
| +) { |
| + |
| + $plugin = "${elasticsearch::directory}/bin/plugin" |
| + |
| + Exec { |
| + cwd => $elasticsearch::directory, |
| + logoutput => true, |
| + notify => Service['elasticsearch'], |
| + require => Package['elasticsearch'], |
| + } |
| + |
| + @exec {"elasticsearch::plugin#install-$name": |
| + command => shellquote($url ? { |
| + undef => [$plugin, '--install', "elasticsearch/$name/$version"], |
| + default => [$plugin, '--install', $name, '--url', $url, '--verbose'], |
| + }), |
| + creates => "${elasticsearch::directory}/plugins/$name", |
| + } |
| + |
| + @exec {"elasticsearch::plugin#remove-$name": |
| + command => shellquote($plugin, '--remove', $name), |
| + onlyif => shellquote('/usr/bin/test', '-e', "plugins/$name"), |
| + } |
| + |
| + if $ensure =~ /^(absent|purged)$/ { |
| + realize(Exec["elasticsearch::plugin#remove-$name"]) |
| + } |
| + elsif $replace == true { |
| + Exec <|title == "elasticsearch::plugin#remove-$name"|> -> |
| + Exec <|title == "elasticsearch::plugin#install-$name"|> |
| + } |
| + else { |
| + realize(Exec["elasticsearch::plugin#install-$name"]) |
| + } |
| +} |