Revert "upgrade to elasticsearch/elasticsearch 0.9.6"
[mirror/dsa-puppet.git] / 3rdparty / modules / elasticsearch / manifests / init.pp
1 # == Class: elasticsearch
2 #
3 # This class is able to install or remove elasticsearch on a node.
4 # It manages the status of the related service.
5 #
6 # === Parameters
7 #
8 # [*ensure*]
9 #   String. Controls if the managed resources shall be <tt>present</tt> or
10 #   <tt>absent</tt>. If set to <tt>absent</tt>:
11 #   * The managed software packages are being uninstalled.
12 #   * Any traces of the packages will be purged as good as possible. This may
13 #     include existing configuration files. The exact behavior is provider
14 #     dependent. Q.v.:
15 #     * Puppet type reference: {package, "purgeable"}[http://j.mp/xbxmNP]
16 #     * {Puppet's package provider source code}[http://j.mp/wtVCaL]
17 #   * System modifications (if any) will be reverted as good as possible
18 #     (e.g. removal of created users, services, changed log settings, ...).
19 #   * This is thus destructive and should be used with care.
20 #   Defaults to <tt>present</tt>.
21 #
22 # [*autoupgrade*]
23 #   Boolean. If set to <tt>true</tt>, any managed package gets upgraded
24 #   on each Puppet run when the package provider is able to find a newer
25 #   version than the present one. The exact behavior is provider dependent.
26 #   Q.v.:
27 #   * Puppet type reference: {package, "upgradeable"}[http://j.mp/xbxmNP]
28 #   * {Puppet's package provider source code}[http://j.mp/wtVCaL]
29 #   Defaults to <tt>false</tt>.
30 #
31 # [*status*]
32 #   String to define the status of the service. Possible values:
33 #   * <tt>enabled</tt>: Service is running and will be started at boot time.
34 #   * <tt>disabled</tt>: Service is stopped and will not be started at boot
35 #     time.
36 #   * <tt>running</tt>: Service is running but will not be started at boot time.
37 #     You can use this to start a service on the first Puppet run instead of
38 #     the system startup.
39 #   * <tt>unmanaged</tt>: Service will not be started at boot time and Puppet
40 #     does not care whether the service is running or not. For example, this may
41 #     be useful if a cluster management software is used to decide when to start
42 #     the service plus assuring it is running on the desired node.
43 #   Defaults to <tt>enabled</tt>. The singular form ("service") is used for the
44 #   sake of convenience. Of course, the defined status affects all services if
45 #   more than one is managed (see <tt>service.pp</tt> to check if this is the
46 #   case).
47 #
48 # [*version*]
49 #   String to set the specific version you want to install.
50 #   Defaults to <tt>false</tt>.
51 #
52 # [*restart_on_change*]
53 #   Boolean that determines if the application should be automatically restarted
54 #   whenever the configuration changes. Disabling automatic restarts on config
55 #   changes may be desired in an environment where you need to ensure restarts
56 #   occur in a controlled/rolling manner rather than during a Puppet run.
57 #
58 #   Defaults to <tt>true</tt>, which will restart the application on any config
59 #   change. Setting to <tt>false</tt> disables the automatic restart.
60 #
61 # [*configdir*]
62 #   Path to directory containing the elasticsearch configuration.
63 #   Use this setting if your packages deviate from the norm (/etc/elasticsearch)
64 #
65 # [*plugindir*]
66 #   Path to directory containing the elasticsearch plugins
67 #   Use this setting if your packages deviate from the norm (/usr/share/elasticsearch/plugins)
68 #
69 # [*plugintool*]
70 #   Path to directory containing the elasticsearch plugin installation script
71 #   Use this setting if your packages deviate from the norm (/usr/share/elasticsearch/bin/plugin)
72 #
73 # [*package_url*]
74 #   Url to the package to download.
75 #   This can be a http,https or ftp resource for remote packages
76 #   puppet:// resource or file:/ for local packages
77 #
78 # [*package_provider*]
79 #   Way to install the packages, currently only packages are supported.
80 #
81 # [*package_dir*]
82 #   Directory where the packages are downloaded to
83 #
84 # [*package_name*]
85 #   Name of the package to install
86 #
87 # [*purge_package_dir*]
88 #   Purge package directory on removal
89 #
90 # [*package_dl_timeout*]
91 #   For http,https and ftp downloads you can set howlong the exec resource may take.
92 #   Defaults to: 600 seconds
93 #
94 # [*elasticsearch_user*]
95 #   The user Elasticsearch should run as. This also sets the file rights.
96 #
97 # [*elasticsearch_group*]
98 #   The group Elasticsearch should run as. This also sets the file rights
99 #
100 # [*purge_configdir*]
101 #   Purge the config directory for any unmanaged files
102 #
103 # [*service_provider*]
104 #   Service provider to use. By Default when a single service provider is possibe that one is selected.
105 #
106 # [*init_defaults*]
107 #   Defaults file content in hash representation
108 #
109 # [*init_defaults_file*]
110 #   Defaults file as puppet resource
111 #
112 # [*init_template*]
113 #   Service file as a template
114 #
115 # [*config*]
116 #   Elasticsearch configuration hash
117 #
118 # [*datadir*]
119 #   Allows you to set the data directory of Elasticsearch
120 #
121 # [*java_install*]
122 #  Install java which is required for Elasticsearch.
123 #  Defaults to: false
124 #
125 # [*java_package*]
126 #   If you like to install a custom java package, put the name here.
127 #
128 # [*manage_repo*]
129 #   Enable repo management by enabling our official repositories
130 #
131 # [*repo_version*]
132 #   Our repositories are versioned per major version (0.90, 1.0) select here which version you want
133 #
134 # [*logging_config*]
135 #   Hash representation of information you want in the logging.yml file
136 #
137 # [*logging_file*]
138 #   Instead of a hash you can supply a puppet:// file source for the logging.yml file
139 #
140 # [*logging_template*]
141 #  Use a custom logging template - just supply the reative path ie ${module}/elasticsearch/logging.yml.erb
142 #
143 # [*default_logging_level*]
144 #   Default logging level for Elasticsearch.
145 #   Defaults to: INFO
146 #
147 # [*repo_stage*]
148 #   Use stdlib stage setup for managing the repo, instead of anchoring
149 #
150 # [*instances*]
151 #   Define instances via a hash. This is mainly used with Hiera's auto binding
152 #   Defaults to: undef
153 #
154 # [*instances_hiera_merge*]
155 #   Enable Hiera's merging function for the instances
156 #   Defaults to: false
157 #
158 # [*plugins*]
159 #   Define plugins via a hash. This is mainly used with Hiera's auto binding
160 #   Defaults to: undef
161 #
162 # [*plugins_hiera_merge*]
163 #   Enable Hiera's merging function for the plugins
164 #   Defaults to: false
165 #
166 # The default values for the parameters are set in elasticsearch::params. Have
167 # a look at the corresponding <tt>params.pp</tt> manifest file if you need more
168 # technical information about them.
169 #
170 # === Examples
171 #
172 # * Installation, make sure service is running and will be started at boot time:
173 #     class { 'elasticsearch': }
174 #
175 # * Removal/decommissioning:
176 #     class { 'elasticsearch':
177 #       ensure => 'absent',
178 #     }
179 #
180 # * Install everything but disable service(s) afterwards
181 #     class { 'elasticsearch':
182 #       status => 'disabled',
183 #     }
184 #
185 #
186 # === Authors
187 #
188 # * Richard Pijnenburg <mailto:richard.pijnenburg@elasticsearch.com>
189 #
190 class elasticsearch(
191   $ensure                = $elasticsearch::params::ensure,
192   $status                = $elasticsearch::params::status,
193   $restart_on_change     = $elasticsearch::params::restart_on_change,
194   $autoupgrade           = $elasticsearch::params::autoupgrade,
195   $version               = false,
196   $package_provider      = 'package',
197   $package_url           = undef,
198   $package_dir           = $elasticsearch::params::package_dir,
199   $package_name          = $elasticsearch::params::package,
200   $purge_package_dir     = $elasticsearch::params::purge_package_dir,
201   $package_dl_timeout    = $elasticsearch::params::package_dl_timeout,
202   $elasticsearch_user    = $elasticsearch::params::elasticsearch_user,
203   $elasticsearch_group   = $elasticsearch::params::elasticsearch_group,
204   $configdir             = $elasticsearch::params::configdir,
205   $purge_configdir       = $elasticsearch::params::purge_configdir,
206   $service_provider      = 'init',
207   $init_defaults         = undef,
208   $init_defaults_file    = undef,
209   $init_template         = undef,
210   $config                = undef,
211   $datadir               = $elasticsearch::params::datadir,
212   $plugindir             = $elasticsearch::params::plugindir,
213   $plugintool            = $elasticsearch::params::plugintool,
214   $java_install          = false,
215   $java_package          = undef,
216   $manage_repo           = false,
217   $repo_version          = undef,
218   $logging_file          = undef,
219   $logging_config        = undef,
220   $logging_template      = undef,
221   $default_logging_level = $elasticsearch::params::default_logging_level,
222   $repo_stage            = false,
223   $instances             = undef,
224   $instances_hiera_merge = false,
225   $plugins               = undef,
226   $plugins_hiera_merge   = false
227 ) inherits elasticsearch::params {
228
229   anchor {'elasticsearch::begin': }
230   anchor {'elasticsearch::end': }
231
232
233   #### Validate parameters
234
235   # ensure
236   if ! ($ensure in [ 'present', 'absent' ]) {
237     fail("\"${ensure}\" is not a valid ensure parameter value")
238   }
239
240   # autoupgrade
241   validate_bool($autoupgrade)
242
243   # service status
244   if ! ($status in [ 'enabled', 'disabled', 'running', 'unmanaged' ]) {
245     fail("\"${status}\" is not a valid status parameter value")
246   }
247
248   # restart on change
249   validate_bool($restart_on_change)
250
251   # purge conf dir
252   validate_bool($purge_configdir)
253
254   if is_array($elasticsearch::params::service_providers) {
255     # Verify the service provider given is in the array
256     if ! ($service_provider in $elasticsearch::params::service_providers) {
257       fail("\"${service_provider}\" is not a valid provider for \"${::operatingsystem}\"")
258     }
259     $real_service_provider = $service_provider
260   } else {
261     # There is only one option so simply set it
262     $real_service_provider = $elasticsearch::params::service_providers
263   }
264
265   if ($package_url != undef and $version != false) {
266     fail('Unable to set the version number when using package_url option.')
267   }
268
269   if $ensure == 'present' {
270     # validate config hash
271     if ($config != undef) {
272       validate_hash($config)
273     }
274   }
275
276   # java install validation
277   validate_bool($java_install)
278
279   validate_bool($manage_repo)
280
281   if ($manage_repo == true) {
282     if $repo_version == undef {
283       fail('Please fill in a repository version at $repo_version')
284     } else {
285       validate_string($repo_version)
286     }
287   }
288
289   #### Manage actions
290
291   # package(s)
292   class { 'elasticsearch::package': }
293
294   # configuration
295   class { 'elasticsearch::config': }
296
297   # Hiera support for instances
298   validate_bool($instances_hiera_merge)
299
300   if $instances_hiera_merge == true {
301     $x_instances = hiera_hash('elasticsearch::instances', $::elasticsearch::instances)
302   } else {
303     $x_instances = $instances
304   }
305
306   if $x_instances {
307     validate_hash($x_instances)
308     create_resources('elasticsearch::instance', $x_instances)
309   }
310
311   # Hiera support for plugins
312   validate_bool($plugins_hiera_merge)
313
314   if $plugins_hiera_merge == true {
315     $x_plugins = hiera_hash('elasticsearch::plugins', $::elasticsearch::plugins)
316   } else {
317     $x_plugins = $plugins
318   }
319
320   if $x_plugins {
321     validate_hash($x_plugins)
322     create_resources('elasticsearch::plugin', $x_plugins)
323   }
324
325
326   if $java_install == true {
327     # Install java
328     class { '::java':
329       package      => $java_package,
330       distribution => 'jre',
331     }
332
333     # ensure we first java java and then manage the service
334     Anchor['elasticsearch::begin']
335     -> Class['::java']
336     -> Class['elasticsearch::package']
337   }
338
339   if ($manage_repo == true) {
340
341     if ($repo_stage == false) {
342       # use anchor for ordering
343
344       # Set up repositories
345       class { 'elasticsearch::repo': }
346
347       # Ensure that we set up the repositories before trying to install
348       # the packages
349       Anchor['elasticsearch::begin']
350       -> Class['elasticsearch::repo']
351       -> Class['elasticsearch::package']
352
353     } else {
354       # use staging for ordering
355
356       if !(defined(Stage[$repo_stage])) {
357         stage { $repo_stage:  before => Stage['main'] }
358       }
359
360       class { 'elasticsearch::repo':
361         stage => $repo_stage,
362       }
363     }
364   }
365
366   #### Manage relationships
367
368   if $ensure == 'present' {
369
370     # we need the software before configuring it
371     Anchor['elasticsearch::begin']
372     -> Class['elasticsearch::package']
373     -> Class['elasticsearch::config']
374     -> Elasticsearch::Instance <| |>
375     -> Elasticsearch::Template <| |>
376   } else {
377
378     # make sure all services are getting stopped before software removal
379     Elasticsearch::Instance <| |>
380     -> Class['elasticsearch::config']
381     -> Class['elasticsearch::package']
382
383   }
384
385 }