|
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 deprecated |
|
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 # [*source*] |
|
31 # Specify the source of the plugin. |
|
32 # This will copy over the plugin to the node and use it for installation. |
|
33 # Useful for offline installation |
|
34 # Value type is string |
|
35 # This variable is optional |
|
36 # |
|
37 # [*proxy_host*] |
|
38 # Proxy host to use when installing the plugin |
|
39 # Value type is string |
|
40 # Default value: None |
|
41 # This variable is optional |
|
42 # |
|
43 # [*proxy_port*] |
|
44 # Proxy port to use when installing the plugin |
|
45 # Value type is number |
|
46 # Default value: None |
|
47 # This variable is optional |
|
48 # |
|
49 # [*instances*] |
|
50 # Specify all the instances related |
|
51 # value type is string or array |
|
52 # |
|
53 # === Examples |
|
54 # |
|
55 # # From official repository |
|
56 # elasticsearch::plugin{'mobz/elasticsearch-head': module_dir => 'head'} |
|
57 # |
|
58 # # From custom url |
|
59 # elasticsearch::plugin{ 'elasticsearch-jetty': |
|
60 # module_dir => 'elasticsearch-jetty', |
|
61 # url => 'https://oss-es-plugins.s3.amazonaws.com/elasticsearch-jetty/elasticsearch-jetty-0.90.0.zip', |
|
62 # } |
|
63 # |
|
64 # === Authors |
|
65 # |
|
66 # * Matteo Sessa <mailto:matteo.sessa@catchoftheday.com.au> |
|
67 # * Dennis Konert <mailto:dkonert@gmail.com> |
|
68 # * Richard Pijnenburg <mailto:richard.pijnenburg@elasticsearch.com> |
|
69 # |
|
70 define elasticsearch::plugin( |
|
71 $instances, |
|
72 $module_dir = undef, |
|
73 $ensure = 'present', |
|
74 $url = undef, |
|
75 $source = undef, |
|
76 $proxy_host = undef, |
|
77 $proxy_port = undef, |
|
78 ) { |
|
79 |
|
80 include elasticsearch |
|
81 |
|
82 $notify_service = $elasticsearch::restart_on_change ? { |
|
83 false => undef, |
|
84 default => Elasticsearch::Service[$instances], |
|
85 } |
|
86 |
|
87 if ($module_dir != undef) { |
|
88 warning("module_dir settings is deprecated for plugin ${name}. The directory is now auto detected.") |
|
89 } |
|
90 |
|
91 # set proxy by override or parse and use proxy_url from |
|
92 # elasticsearch::proxy_url or use no proxy at all |
|
93 |
|
94 if ($proxy_host != undef and $proxy_port != undef) { |
|
95 $proxy = "-DproxyPort=${proxy_port} -DproxyHost=${proxy_host}" |
|
96 } |
|
97 elsif ($elasticsearch::proxy_url != undef) { |
|
98 $proxy_host_from_url = regsubst($elasticsearch::proxy_url, '(http|https)://([^:]+)(|:\d+).+', '\2') |
|
99 $proxy_port_from_url = regsubst($elasticsearch::proxy_url, '(?:http|https)://[^:/]+(?::([0-9]+))?(?:/.*)?', '\1') |
|
100 |
|
101 # validate parsed values before using them |
|
102 if (is_string($proxy_host_from_url) and is_integer($proxy_port_from_url)) { |
|
103 $proxy = "-DproxyPort=${proxy_port_from_url} -DproxyHost=${proxy_host_from_url}" |
|
104 } |
|
105 } |
|
106 else { |
|
107 $proxy = undef |
|
108 } |
|
109 |
|
110 if ($source != undef) { |
|
111 |
|
112 $filenameArray = split($source, '/') |
|
113 $basefilename = $filenameArray[-1] |
|
114 |
|
115 $file_source = "${elasticsearch::package_dir}/${basefilename}" |
|
116 |
|
117 file { $file_source: |
|
118 ensure => 'file', |
|
119 source => $source, |
|
120 } |
|
121 |
|
122 } elsif ($url != undef) { |
|
123 validate_string($url) |
|
124 } |
|
125 |
|
126 case $ensure { |
|
127 'installed', 'present': { |
|
128 |
|
129 elasticsearch_plugin { $name: |
|
130 ensure => 'present', |
|
131 source => $file_source, |
|
132 url => $url, |
|
133 proxy_args => $proxy, |
|
134 notify => $notify_service, |
|
135 } |
|
136 |
|
137 } |
|
138 'absent': { |
|
139 elasticsearch_plugin { $name: |
|
140 ensure => absent, |
|
141 } |
|
142 } |
|
143 default: { |
|
144 fail("${ensure} is not a valid ensure command.") |
|
145 } |
|
146 } |
|
147 } |