]> git.donarmstrong.com Git - dsa-puppet.git/blob - 3rdparty/modules/elasticsearch/manifests/init.pp
upgrade to elasticsearch/elasticsearch 0.9.6
[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 # [*package_pin*]
167 #   Enables package version pinning.
168 #   This pins the package version to the set version number and avoids
169 #   package upgrades.
170 #   Defaults to: true
171 #
172 # The default values for the parameters are set in elasticsearch::params. Have
173 # a look at the corresponding <tt>params.pp</tt> manifest file if you need more
174 # technical information about them.
175 #
176 # === Examples
177 #
178 # * Installation, make sure service is running and will be started at boot time:
179 #     class { 'elasticsearch': }
180 #
181 # * Removal/decommissioning:
182 #     class { 'elasticsearch':
183 #       ensure => 'absent',
184 #     }
185 #
186 # * Install everything but disable service(s) afterwards
187 #     class { 'elasticsearch':
188 #       status => 'disabled',
189 #     }
190 #
191 #
192 # === Authors
193 #
194 # * Richard Pijnenburg <mailto:richard.pijnenburg@elasticsearch.com>
195 #
196 class elasticsearch(
197   $ensure                = $elasticsearch::params::ensure,
198   $status                = $elasticsearch::params::status,
199   $restart_on_change     = $elasticsearch::params::restart_on_change,
200   $autoupgrade           = $elasticsearch::params::autoupgrade,
201   $version               = false,
202   $package_provider      = 'package',
203   $package_url           = undef,
204   $package_dir           = $elasticsearch::params::package_dir,
205   $package_name          = $elasticsearch::params::package,
206   $package_pin           = true,
207   $purge_package_dir     = $elasticsearch::params::purge_package_dir,
208   $package_dl_timeout    = $elasticsearch::params::package_dl_timeout,
209   $elasticsearch_user    = $elasticsearch::params::elasticsearch_user,
210   $elasticsearch_group   = $elasticsearch::params::elasticsearch_group,
211   $configdir             = $elasticsearch::params::configdir,
212   $purge_configdir       = $elasticsearch::params::purge_configdir,
213   $service_provider      = 'init',
214   $init_defaults         = undef,
215   $init_defaults_file    = undef,
216   $init_template         = undef,
217   $config                = undef,
218   $datadir               = $elasticsearch::params::datadir,
219   $plugindir             = $elasticsearch::params::plugindir,
220   $plugintool            = $elasticsearch::params::plugintool,
221   $java_install          = false,
222   $java_package          = undef,
223   $manage_repo           = false,
224   $repo_version          = undef,
225   $logging_file          = undef,
226   $logging_config        = undef,
227   $logging_template      = undef,
228   $default_logging_level = $elasticsearch::params::default_logging_level,
229   $repo_stage            = false,
230   $instances             = undef,
231   $instances_hiera_merge = false,
232   $plugins               = undef,
233   $plugins_hiera_merge   = false
234 ) inherits elasticsearch::params {
235
236   anchor {'elasticsearch::begin': }
237
238
239   #### Validate parameters
240
241   # ensure
242   if ! ($ensure in [ 'present', 'absent' ]) {
243     fail("\"${ensure}\" is not a valid ensure parameter value")
244   }
245
246   # autoupgrade
247   validate_bool($autoupgrade)
248
249   # service status
250   if ! ($status in [ 'enabled', 'disabled', 'running', 'unmanaged' ]) {
251     fail("\"${status}\" is not a valid status parameter value")
252   }
253
254   # restart on change
255   validate_bool($restart_on_change)
256
257   # purge conf dir
258   validate_bool($purge_configdir)
259
260   if is_array($elasticsearch::params::service_providers) {
261     # Verify the service provider given is in the array
262     if ! ($service_provider in $elasticsearch::params::service_providers) {
263       fail("\"${service_provider}\" is not a valid provider for \"${::operatingsystem}\"")
264     }
265     $real_service_provider = $service_provider
266   } else {
267     # There is only one option so simply set it
268     $real_service_provider = $elasticsearch::params::service_providers
269   }
270
271   if ($package_url != undef and $version != false) {
272     fail('Unable to set the version number when using package_url option.')
273   }
274
275   if $ensure == 'present' {
276     # validate config hash
277     if ($config != undef) {
278       validate_hash($config)
279     }
280   }
281
282   # java install validation
283   validate_bool($java_install)
284
285   validate_bool($manage_repo)
286
287   if ($manage_repo == true) {
288     if $repo_version == undef {
289       fail('Please fill in a repository version at $repo_version')
290     } else {
291       validate_string($repo_version)
292     }
293   }
294
295   #### Manage actions
296
297   # package(s)
298   class { 'elasticsearch::package': }
299
300   # configuration
301   class { 'elasticsearch::config': }
302
303   # Hiera support for instances
304   validate_bool($instances_hiera_merge)
305
306   if $instances_hiera_merge == true {
307     $x_instances = hiera_hash('elasticsearch::instances', $::elasticsearch::instances)
308   } else {
309     $x_instances = $instances
310   }
311
312   if $x_instances {
313     validate_hash($x_instances)
314     create_resources('elasticsearch::instance', $x_instances)
315   }
316
317   # Hiera support for plugins
318   validate_bool($plugins_hiera_merge)
319
320   if $plugins_hiera_merge == true {
321     $x_plugins = hiera_hash('elasticsearch::plugins', $::elasticsearch::plugins)
322   } else {
323     $x_plugins = $plugins
324   }
325
326   if $x_plugins {
327     validate_hash($x_plugins)
328     create_resources('elasticsearch::plugin', $x_plugins)
329   }
330
331
332   if $java_install == true {
333     # Install java
334     class { '::java':
335       package      => $java_package,
336       distribution => 'jre',
337     }
338
339     # ensure we first install java, the package and then the rest
340     Anchor['elasticsearch::begin']
341     -> Class['::java']
342     -> Class['elasticsearch::package']
343   }
344
345   if ($manage_repo == true) {
346
347     if ($repo_stage == false) {
348       # use anchor for ordering
349
350       # Set up repositories
351       class { 'elasticsearch::repo': }
352
353       # Ensure that we set up the repositories before trying to install
354       # the packages
355       Anchor['elasticsearch::begin']
356       -> Class['elasticsearch::repo']
357       -> Class['elasticsearch::package']
358
359     } else {
360       # use staging for ordering
361
362       if !(defined(Stage[$repo_stage])) {
363         stage { $repo_stage:  before => Stage['main'] }
364       }
365
366       class { 'elasticsearch::repo':
367         stage => $repo_stage,
368       }
369     }
370   }
371
372   #### Manage relationships
373
374   if $ensure == 'present' {
375
376     # we need the software before configuring it
377     Anchor['elasticsearch::begin']
378     -> Class['elasticsearch::package']
379     -> Class['elasticsearch::config']
380     -> Elasticsearch::Instance <| |>
381     -> Elasticsearch::Template <| |>
382
383   } else {
384
385     # make sure all services are getting stopped before software removal
386     Anchor['elasticsearch::begin']
387     -> Elasticsearch::Instance <| |>
388     -> Class['elasticsearch::config']
389     -> Class['elasticsearch::package']
390
391   }
392
393 }