1 # == Class: elasticsearch
3 # This class is able to install or remove elasticsearch on a node.
4 # It manages the status of the related service.
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
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>.
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.
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>.
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
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
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
49 # String to set the specific version you want to install.
50 # Defaults to <tt>false</tt>.
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.
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.
62 # Path to directory containing the elasticsearch configuration.
63 # Use this setting if your packages deviate from the norm (/etc/elasticsearch)
66 # Path to directory containing the elasticsearch plugins
67 # Use this setting if your packages deviate from the norm (/usr/share/elasticsearch/plugins)
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)
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
78 # [*package_provider*]
79 # Way to install the packages, currently only packages are supported.
82 # Directory where the packages are downloaded to
85 # Name of the package to install
87 # [*purge_package_dir*]
88 # Purge package directory on removal
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
94 # [*elasticsearch_user*]
95 # The user Elasticsearch should run as. This also sets the file rights.
97 # [*elasticsearch_group*]
98 # The group Elasticsearch should run as. This also sets the file rights
100 # [*purge_configdir*]
101 # Purge the config directory for any unmanaged files
103 # [*service_provider*]
104 # Service provider to use. By Default when a single service provider is possibe that one is selected.
107 # Defaults file content in hash representation
109 # [*init_defaults_file*]
110 # Defaults file as puppet resource
113 # Service file as a template
116 # Elasticsearch configuration hash
119 # Allows you to set the data directory of Elasticsearch
122 # Install java which is required for Elasticsearch.
126 # If you like to install a custom java package, put the name here.
129 # Enable repo management by enabling our official repositories
132 # Our repositories are versioned per major version (0.90, 1.0) select here which version you want
135 # Hash representation of information you want in the logging.yml file
138 # Instead of a hash you can supply a puppet:// file source for the logging.yml file
140 # [*logging_template*]
141 # Use a custom logging template - just supply the reative path ie ${module}/elasticsearch/logging.yml.erb
143 # [*default_logging_level*]
144 # Default logging level for Elasticsearch.
148 # Use stdlib stage setup for managing the repo, instead of anchoring
151 # Define instances via a hash. This is mainly used with Hiera's auto binding
154 # [*instances_hiera_merge*]
155 # Enable Hiera's merging function for the instances
159 # Define plugins via a hash. This is mainly used with Hiera's auto binding
162 # [*plugins_hiera_merge*]
163 # Enable Hiera's merging function for the plugins
167 # Enables package version pinning.
168 # This pins the package version to the set version number and avoids
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.
178 # * Installation, make sure service is running and will be started at boot time:
179 # class { 'elasticsearch': }
181 # * Removal/decommissioning:
182 # class { 'elasticsearch':
183 # ensure => 'absent',
186 # * Install everything but disable service(s) afterwards
187 # class { 'elasticsearch':
188 # status => 'disabled',
194 # * Richard Pijnenburg <mailto:richard.pijnenburg@elasticsearch.com>
197 $ensure = $elasticsearch::params::ensure,
198 $status = $elasticsearch::params::status,
199 $restart_on_change = $elasticsearch::params::restart_on_change,
200 $autoupgrade = $elasticsearch::params::autoupgrade,
202 $package_provider = 'package',
203 $package_url = undef,
204 $package_dir = $elasticsearch::params::package_dir,
205 $package_name = $elasticsearch::params::package,
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,
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,
231 $instances_hiera_merge = false,
233 $plugins_hiera_merge = false
234 ) inherits elasticsearch::params {
236 anchor {'elasticsearch::begin': }
239 #### Validate parameters
242 if ! ($ensure in [ 'present', 'absent' ]) {
243 fail("\"${ensure}\" is not a valid ensure parameter value")
247 validate_bool($autoupgrade)
250 if ! ($status in [ 'enabled', 'disabled', 'running', 'unmanaged' ]) {
251 fail("\"${status}\" is not a valid status parameter value")
255 validate_bool($restart_on_change)
258 validate_bool($purge_configdir)
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}\"")
265 $real_service_provider = $service_provider
267 # There is only one option so simply set it
268 $real_service_provider = $elasticsearch::params::service_providers
271 if ($package_url != undef and $version != false) {
272 fail('Unable to set the version number when using package_url option.')
275 if $ensure == 'present' {
276 # validate config hash
277 if ($config != undef) {
278 validate_hash($config)
282 # java install validation
283 validate_bool($java_install)
285 validate_bool($manage_repo)
287 if ($manage_repo == true) {
288 if $repo_version == undef {
289 fail('Please fill in a repository version at $repo_version')
291 validate_string($repo_version)
298 class { 'elasticsearch::package': }
301 class { 'elasticsearch::config': }
303 # Hiera support for instances
304 validate_bool($instances_hiera_merge)
306 if $instances_hiera_merge == true {
307 $x_instances = hiera_hash('elasticsearch::instances', $::elasticsearch::instances)
309 $x_instances = $instances
313 validate_hash($x_instances)
314 create_resources('elasticsearch::instance', $x_instances)
317 # Hiera support for plugins
318 validate_bool($plugins_hiera_merge)
320 if $plugins_hiera_merge == true {
321 $x_plugins = hiera_hash('elasticsearch::plugins', $::elasticsearch::plugins)
323 $x_plugins = $plugins
327 validate_hash($x_plugins)
328 create_resources('elasticsearch::plugin', $x_plugins)
332 if $java_install == true {
335 package => $java_package,
336 distribution => 'jre',
339 # ensure we first install java, the package and then the rest
340 Anchor['elasticsearch::begin']
342 -> Class['elasticsearch::package']
345 if ($manage_repo == true) {
347 if ($repo_stage == false) {
348 # use anchor for ordering
350 # Set up repositories
351 class { 'elasticsearch::repo': }
353 # Ensure that we set up the repositories before trying to install
355 Anchor['elasticsearch::begin']
356 -> Class['elasticsearch::repo']
357 -> Class['elasticsearch::package']
360 # use staging for ordering
362 if !(defined(Stage[$repo_stage])) {
363 stage { $repo_stage: before => Stage['main'] }
366 class { 'elasticsearch::repo':
367 stage => $repo_stage,
372 #### Manage relationships
374 if $ensure == 'present' {
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 <| |>
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']