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
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.
172 # * Installation, make sure service is running and will be started at boot time:
173 # class { 'elasticsearch': }
175 # * Removal/decommissioning:
176 # class { 'elasticsearch':
177 # ensure => 'absent',
180 # * Install everything but disable service(s) afterwards
181 # class { 'elasticsearch':
182 # status => 'disabled',
188 # * Richard Pijnenburg <mailto:richard.pijnenburg@elasticsearch.com>
191 $ensure = $elasticsearch::params::ensure,
192 $status = $elasticsearch::params::status,
193 $restart_on_change = $elasticsearch::params::restart_on_change,
194 $autoupgrade = $elasticsearch::params::autoupgrade,
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,
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,
224 $instances_hiera_merge = false,
226 $plugins_hiera_merge = false
227 ) inherits elasticsearch::params {
229 anchor {'elasticsearch::begin': }
230 anchor {'elasticsearch::end': }
233 #### Validate parameters
236 if ! ($ensure in [ 'present', 'absent' ]) {
237 fail("\"${ensure}\" is not a valid ensure parameter value")
241 validate_bool($autoupgrade)
244 if ! ($status in [ 'enabled', 'disabled', 'running', 'unmanaged' ]) {
245 fail("\"${status}\" is not a valid status parameter value")
249 validate_bool($restart_on_change)
252 validate_bool($purge_configdir)
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}\"")
259 $real_service_provider = $service_provider
261 # There is only one option so simply set it
262 $real_service_provider = $elasticsearch::params::service_providers
265 if ($package_url != undef and $version != false) {
266 fail('Unable to set the version number when using package_url option.')
269 if $ensure == 'present' {
270 # validate config hash
271 if ($config != undef) {
272 validate_hash($config)
276 # java install validation
277 validate_bool($java_install)
279 validate_bool($manage_repo)
281 if ($manage_repo == true) {
282 if $repo_version == undef {
283 fail('Please fill in a repository version at $repo_version')
285 validate_string($repo_version)
292 class { 'elasticsearch::package': }
295 class { 'elasticsearch::config': }
297 # Hiera support for instances
298 validate_bool($instances_hiera_merge)
300 if $instances_hiera_merge == true {
301 $x_instances = hiera_hash('elasticsearch::instances', $::elasticsearch::instances)
303 $x_instances = $instances
307 validate_hash($x_instances)
308 create_resources('elasticsearch::instance', $x_instances)
311 # Hiera support for plugins
312 validate_bool($plugins_hiera_merge)
314 if $plugins_hiera_merge == true {
315 $x_plugins = hiera_hash('elasticsearch::plugins', $::elasticsearch::plugins)
317 $x_plugins = $plugins
321 validate_hash($x_plugins)
322 create_resources('elasticsearch::plugin', $x_plugins)
326 if $java_install == true {
329 package => $java_package,
330 distribution => 'jre'
333 # ensure we first java java and then manage the service
334 Anchor['elasticsearch::begin']
336 -> Class['elasticsearch::package']
339 if ($manage_repo == true) {
341 if ($repo_stage == false) {
342 # use anchor for ordering
344 # Set up repositories
345 class { 'elasticsearch::repo': }
347 # Ensure that we set up the repositories before trying to install
349 Anchor['elasticsearch::begin']
350 -> Class['elasticsearch::repo']
351 -> Class['elasticsearch::package']
354 # use staging for ordering
356 if !(defined(Stage[$repo_stage])) {
357 stage { $repo_stage: before => Stage['main'] }
360 class { 'elasticsearch::repo':
366 #### Manage relationships
368 if $ensure == 'present' {
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 <| |>
378 # make sure all services are getting stopped before software removal
379 Elasticsearch::Instance <| |>
380 -> Class['elasticsearch::config']
381 -> Class['elasticsearch::package']