f49a6bd3ea095587bfa14b3c391f8b6d256681aa
[mirror/dsa-puppet.git] / 3rdparty / modules / elasticsearch / manifests / plugin.pp
1 # == Define: elasticsearch::plugin
2 #
3 # This define allows you to install arbitrary Elasticsearch plugins
4 # either by using the default repositories or by specifying an URL
5 #
6 # All default values are defined in the elasticsearch::params class.
7 #
8 #
9 # === Parameters
10 #
11 # [*module_dir*]
12 #   Directory name where the module will be installed
13 #   Value type is string
14 #   Default value: None
15 #   This variable is required
16 #
17 # [*ensure*]
18 #   Whether the plugin will be installed or removed.
19 #   Set to 'absent' to ensure a plugin is not installed
20 #   Value type is string
21 #   Default value: present
22 #   This variable is optional
23 #
24 # [*url*]
25 #   Specify an URL where to download the plugin from.
26 #   Value type is string
27 #   Default value: None
28 #   This variable is optional
29 #
30 # [*proxy_host*]
31 #   Proxy host to use when installing the plugin
32 #   Value type is string
33 #   Default value: None
34 #   This variable is optional
35 #
36 # [*proxy_port*]
37 #   Proxy port to use when installing the plugin
38 #   Value type is number
39 #   Default value: None
40 #   This variable is optional
41 #
42 # [*instances*]
43 #   Specify all the instances related
44 #   value type is string or array
45 #
46 # === Examples
47 #
48 # # From official repository
49 # elasticsearch::plugin{'mobz/elasticsearch-head': module_dir => 'head'}
50 #
51 # # From custom url
52 # elasticsearch::plugin{ 'elasticsearch-jetty':
53 #  module_dir => 'elasticsearch-jetty',
54 #  url        => 'https://oss-es-plugins.s3.amazonaws.com/elasticsearch-jetty/elasticsearch-jetty-0.90.0.zip',
55 # }
56 #
57 # === Authors
58 #
59 # * Matteo Sessa <mailto:matteo.sessa@catchoftheday.com.au>
60 # * Dennis Konert <mailto:dkonert@gmail.com>
61 # * Richard Pijnenburg <mailto:richard.pijnenburg@elasticsearch.com>
62 #
63 define elasticsearch::plugin(
64     $module_dir,
65     $instances,
66     $ensure      = 'present',
67     $url         = '',
68     $proxy_host  = undef,
69     $proxy_port  = undef,
70 ) {
71
72   include elasticsearch
73
74   Exec {
75     path      => [ '/bin', '/usr/bin', '/usr/local/bin' ],
76     cwd       => '/',
77     user      => $elasticsearch::elasticsearch_user,
78     tries     => 6,
79     try_sleep => 10
80   }
81
82   $notify_service = $elasticsearch::restart_on_change ? {
83     false   => undef,
84     default => Elasticsearch::Service[$instances],
85   }
86
87   if ($module_dir != '') {
88       validate_string($module_dir)
89   } else {
90       fail("module_dir undefined for plugin ${name}")
91   }
92
93   if ($proxy_host != undef and $proxy_port != undef) {
94     $proxy = " -DproxyPort=${proxy_port} -DproxyHost=${proxy_host}"
95   } else {
96     $proxy = ''
97   }
98
99   if ($url != '') {
100     validate_string($url)
101     $install_cmd = "${elasticsearch::plugintool}${proxy} -install ${name} -url ${url}"
102     $exec_rets = [0,1]
103   } else {
104     $install_cmd = "${elasticsearch::plugintool}${proxy} -install ${name}"
105     $exec_rets = [0,]
106   }
107
108   case $ensure {
109     'installed', 'present': {
110       exec {"install_plugin_${name}":
111         command => $install_cmd,
112         creates => "${elasticsearch::plugindir}/${module_dir}",
113         returns => $exec_rets,
114         notify  => $notify_service,
115         require => File[$elasticsearch::plugindir]
116       }
117     }
118     default: {
119       exec {"remove_plugin_${name}":
120         command => "${elasticsearch::plugintool} --remove ${module_dir}",
121         onlyif  => "test -d ${elasticsearch::plugindir}/${module_dir}",
122         notify  => $notify_service,
123       }
124     }
125   }
126 }