Puppet Class: elasticsearch

Inherits:
elasticsearch::params
Defined in:
manifests/init.pp

Summary

Manages the installation of Elasticsearch and related options.

Overview

Top-level Elasticsearch class which may manage installation of the Elasticsearch package, package repository, java package, and other global options and parameters.

Examples:

install Elasticsearch

class { 'elasticsearch': }

removal and decommissioning

class { 'elasticsearch':
  ensure => 'absent',
}

install everything but disable service(s) afterwards

class { 'elasticsearch':
  status => 'disabled',
}

Parameters:

  • ensure (String) (defaults to: 'present')

    Controls if the managed resources shall be ‘present` or `absent`. If set to `absent`, the managed software packages will be uninstalled, and any traces of the packages will be purged as well as possible, possibly including existing configuration files. System modifications (if any) will be reverted as well as possible (e.g. removal of created users, services, changed log settings, and so on). This is a destructive parameter and should be used with care.

  • api_basic_auth_password (String) (defaults to: undef)

    Defines the default REST basic auth password for API authentication.

  • api_basic_auth_username (String) (defaults to: undef)

    Defines the default REST basic auth username for API authentication.

  • api_ca_file (String) (defaults to: undef)

    Path to a CA file which will be used to validate server certs when communicating with the Elasticsearch API over HTTPS.

  • api_ca_path (String) (defaults to: undef)

    Path to a directory with CA files which will be used to validate server certs when communicating with the Elasticsearch API over HTTPS.

  • api_host (String) (defaults to: 'localhost')

    Default host to use when accessing Elasticsearch APIs.

  • api_port (Integer) (defaults to: 9200)

    Default port to use when accessing Elasticsearch APIs.

  • api_protocol (String) (defaults to: 'http')

    Default protocol to use when accessing Elasticsearch APIs.

  • api_timeout (Integer) (defaults to: 10)

    Default timeout (in seconds) to use when accessing Elasticsearch APIs.

  • autoupgrade (Boolean) (defaults to: false)

    If set to ‘true`, any managed package will be upgraded on each Puppet run when the package provider is able to find a newer version than the present one. The exact behavior is provider dependent (see package, “upgradeable” in the Puppet documentation).

  • config (Hash) (defaults to: undef)

    Elasticsearch configuration hash.

  • config_hiera_merge (Boolean) (defaults to: false)

    Enable Hiera merging for the config hash.

  • configdir (String) (defaults to: $elasticsearch::params::configdir)

    Directory containing the elasticsearch configuration. Use this setting if your packages deviate from the norm (‘/etc/elasticsearch`)

  • daily_rolling_date_pattern (String) (defaults to: '"\'.\'yyyy-MM-dd"')

    File pattern for the file appender log when file_rolling_type is ‘dailyRollingFile’.

  • datadir (String) (defaults to: $elasticsearch::params::datadir)

    Allows you to set the data directory of Elasticsearch.

  • datadir_instance_directories (Boolean) (defaults to: true)

    Control whether individual directories for instances will be created within each instance’s data directorry.

  • default_logging_level (String) (defaults to: 'INFO')

    Default logging level for Elasticsearch.

  • elasticsearch_group (String) (defaults to: $elasticsearch::params::elasticsearch_group)

    The group Elasticsearch should run as. This also sets file group permissions.

  • elasticsearch_user (String) (defaults to: $elasticsearch::params::elasticsearch_user)

    The user Elasticsearch should run as. This also sets file ownership.

  • file_rolling_type (String) (defaults to: 'dailyRollingFile')

    Configuration for the file appender rotation. It can be ‘dailyRollingFile’ or ‘rollingFile’. The first rotates by name, and the second one by size.

  • indices (Hash) (defaults to: undef)

    Define indices via a hash. This is mainly used with Hiera’s auto binding.

  • indices_hiera_merge (Boolean) (defaults to: false)

    Enable Hiera’s merging function for indices.

  • init_defaults (Hash) (defaults to: undef)

    Defaults file content in hash representation.

  • init_defaults_file (String) (defaults to: undef)

    Defaults file as puppet resource.

  • init_template (String) (defaults to: "${module_name}/etc/init.d/${elasticsearch::params::init_template}")

    Service file as a template.

  • instances (Hash) (defaults to: undef)

    Define instances via a hash. This is mainly used with Hiera’s auto binding.

  • instances_hiera_merge (Boolean) (defaults to: false)

    Enable Hiera’s merging function for the instances.

  • java_install (Boolean) (defaults to: false)

    Install java which is required for Elasticsearch.

  • java_package (String) (defaults to: undef)

    Custom java package to be used when managing Java with ‘java_install`.

  • jvm_options (Array) (defaults to: [])

    Array of options to set in jvm_options.

  • log4j2_ensure (String) (defaults to: 'file')

    State of the log4j2 logging configuration file.

  • logdir (String) (defaults to: '/var/log/elasticsearch')

    Directory that will be used for Elasticsearch logging.

  • logging_config (Hash) (defaults to: undef)

    Representation of information to be included in the logging.yml file.

  • logging_file (String) (defaults to: undef)

    Instead of a hash, you may supply a ‘puppet://` file source for the logging.yml file.

  • logging_template (String) (defaults to: undef)

    Use a custom logging template - just supply the relative path, i.e. ‘$module/elasticsearch/logging.yml.erb`

  • logging_yml_ensure (String) (defaults to: 'file')

    State of the logging.yml logging configuration file.

  • manage_repo (Boolean) (defaults to: false)

    Enable repo management by enabling official Elastic repositories.

  • package_dir (String) (defaults to: $elasticsearch::params::package_dir)

    Directory where packages are downloaded to.

  • package_dl_timeout (Integer) (defaults to: 600)

    For http, https, and ftp downloads, you may set how long the exec resource may take.

  • package_name (String) (defaults to: $elasticsearch::params::package)

    Name Of the package to install.

  • package_pin (Boolean) (defaults to: true)

    Enables package version pinning. This pins the package version to the set version number and avoids package upgrades.

  • package_provider (String) (defaults to: 'package')

    Method to install the packages, currently only ‘package` is supported.

  • package_url (String) (defaults to: undef)

    URL of the package to download. This can be an http, https, or ftp resource for remote packages, or a ‘puppet://` resource or `file:/` for local packages

  • pipelines (Hash) (defaults to: undef)

    Define pipelines via a hash. This is mainly used with Hiera’s auto binding.

  • pipelines_hiera_merge (Boolean) (defaults to: false)

    Enable Hiera’s merging function for pipelines.

  • plugindir (String) (defaults to: $elasticsearch::params::plugindir)

    Directory containing elasticsearch plugins. Use this setting if your packages deviate from the norm (/usr/share/elasticsearch/plugins)

  • plugins (Hash) (defaults to: undef)

    Define plugins via a hash. This is mainly used with Hiera’s auto binding.

  • plugins_hiera_merge (Boolean) (defaults to: false)

    Enable Hiera’s merging function for the plugins.

  • proxy_url (String) (defaults to: undef)

    For http and https downloads, you may set a proxy server to use. By default, no proxy is used. Format: ‘proto://[user:pass@]server/`

  • purge_configdir (Boolean) (defaults to: false)

    Purge the config directory of any unmanaged files.

  • purge_package_dir (Boolean) (defaults to: false)

    Purge package directory on removal

  • purge_secrets (Boolean) (defaults to: false)

    Whether or not keys present in the keystore will be removed if they are not present in the specified secrets hash.

  • repo_baseurl (String) (defaults to: undef)

    If a custom repository URL is needed (such as for installations behind restrictive firewalls), this parameter overrides the upstream repository URL. Note that any additional changes to the repository metdata (such as signing keys and so on) will need to be handled appropriately.

  • repo_key_id (String) (defaults to: '46095ACC8548582C1A2699A9D27D666CD88E42B4')

    The apt GPG key id.

  • repo_key_source (String) (defaults to: 'https://artifacts.elastic.co/GPG-KEY-elasticsearch')

    URL of the repository GPG key.

  • repo_priority (Integer) (defaults to: undef)

    Repository priority. yum and apt supported.

  • repo_proxy (String) (defaults to: undef)

    URL for repository proxy.

  • repo_stage (Boolean) (defaults to: false)

    Use stdlib stage setup for managing the repo instead of anchoring.

  • repo_version (String) (defaults to: undef)

    Elastic repositories are versioned per major version (0.90, 1.0). This parameter controls which version to use.

  • restart_on_change (Boolean) (defaults to: $elasticsearch::params::restart_on_change)

    Determines if the application should be automatically restarted whenever the configuration, package, or plugins change. Enabling this setting will cause Elasticsearch to restart whenever there is cause to re-read configuration files, load new plugins, or start the service using an updated/changed executable. This may be undesireable in highly available environments. If all other restart_* parameters are left unset, the value of ‘restart_on_change` is used for all other restart_*_change defaults.

  • restart_config_change (Boolean) (defaults to: $elasticsearch::restart_on_change)

    Determines if the application should be automatically restarted whenever the configuration changes. This includes the Elasticsearch configuration file, any service files, and defaults files. Disabling automatic restarts on config changes may be desired in an environment where you need to ensure restarts occur in a controlled/rolling manner rather than during a Puppet run.

  • restart_package_change (Boolean) (defaults to: $elasticsearch::restart_on_change)

    Determines if the application should be automatically restarted whenever the package (or package version) for Elasticsearch changes. Disabling automatic restarts on package changes may be desired in an environment where you need to ensure restarts occur in a controlled/rolling manner rather than during a Puppet run.

  • restart_plugin_change (Boolean) (defaults to: $elasticsearch::restart_on_change)

    Determines if the application should be automatically restarted whenever plugins are installed or removed. Disabling automatic restarts on plugin changes may be desired in an environment where you need to ensure restarts occur in a controlled/rolling manner rather than during a Puppet run.

  • roles (Hash) (defaults to: undef)

    Define roles via a hash. This is mainly used with Hiera’s auto binding.

  • roles_hiera_merge (Boolean) (defaults to: false)

    Enable Hiera’s merging function for roles.

  • rolling_file_max_backup_index (Integer) (defaults to: 1)

    Max number of logs to store whern file_rolling_type is ‘rollingFile’

  • rolling_file_max_file_size (String) (defaults to: '10MB')

    Max log file size when file_rolling_type is ‘rollingFile’

  • scripts (Hash) (defaults to: undef)

    Define scripts via a hash. This is mainly used with Hiera’s auto binding.

  • scripts_hiera_merge (Boolean) (defaults to: false)

    Enable Hiera’s merging function for scripts.

  • secrets (Hash) (defaults to: undef)

    Optional default configuration hash of key/value pairs to store in the Elasticsearch keystore file. If unset, the keystore is left unmanaged.

  • security_logging_content (String) (defaults to: undef)

    File content for shield/x-pack logging configuration file (will be placed into logging.yml or log4j2.properties file as appropriate).

  • security_logging_source (String) (defaults to: undef)

    File source for shield/x-pack logging configuration file (will be placed into logging.yml or log4j2.properties file as appropriate).

  • security_plugin (String) (defaults to: undef)

    Which security plugin will be used to manage users, roles, and certificates. Valid values are ‘shield’ and ‘x-pack’.

  • service_provider (String) (defaults to: 'init')

    Service provider to use. By Default when a single service provider is possible, that one is selected.

  • status (String) (defaults to: 'enabled')

    To define the status of the service. If set to ‘enabled`, the service will be run and will be started at boot time. If set to `disabled`, the service is stopped and will not be started at boot time. If set to `running`, the service will be run but will not be started at boot time. You may use this to start a service on the first Puppet run instead of the system startup. If set to `unmanaged`, the service will not be started at boot time and Puppet does not care whether the service is running or not. For example, this may be useful if a cluster management software is used to decide when to start the service plus assuring it is running on the desired node.

  • system_key (String) (defaults to: undef)

    Source for the Shield/x-pack system key. Valid values are any that are supported for the file resource ‘source` parameter.

  • templates (Hash) (defaults to: undef)

    Define templates via a hash. This is mainly used with Hiera’s auto binding.

  • templates_hiera_merge (Boolean) (defaults to: false)

    Enable Hiera’s merging function for templates.

  • users (Hash) (defaults to: undef)

    Define templates via a hash. This is mainly used with Hiera’s auto binding.

  • users_hiera_merge (Boolean) (defaults to: false)

    Enable Hiera’s merging function for users.

  • validate_tls (Boolean) (defaults to: true)

    Enable TLS/SSL validation on API calls.

  • version (String) (defaults to: false)

    To set the specific version you want to install.

Author:

  • Richard Pijnenburg <richard.pijnenburg@elasticsearch.com>

  • Tyler Langlois <tyler.langlois@elastic.co>



332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
# File 'manifests/init.pp', line 332

class elasticsearch(
  $ensure                         = 'present',
  $api_basic_auth_password        = undef,
  $api_basic_auth_username        = undef,
  $api_ca_file                    = undef,
  $api_ca_path                    = undef,
  $api_host                       = 'localhost',
  $api_port                       = 9200,
  $api_protocol                   = 'http',
  $api_timeout                    = 10,
  $autoupgrade                    = false,
  $config                         = undef,
  $config_hiera_merge             = false,
  $configdir                      = $elasticsearch::params::configdir,
  $daily_rolling_date_pattern     = '"\'.\'yyyy-MM-dd"',
  $datadir                        = $elasticsearch::params::datadir,
  $datadir_instance_directories   = true,
  $default_logging_level          = 'INFO',
  $elasticsearch_group            = $elasticsearch::params::elasticsearch_group,
  $elasticsearch_user             = $elasticsearch::params::elasticsearch_user,
  $file_rolling_type              = 'dailyRollingFile',
  $indices                        = undef,
  $indices_hiera_merge            = false,
  $init_defaults                  = undef,
  $init_defaults_file             = undef,
  $init_template                  = "${module_name}/etc/init.d/${elasticsearch::params::init_template}",
  $instances                      = undef,
  $instances_hiera_merge          = false,
  $java_install                   = false,
  $java_package                   = undef,
  $jvm_options                    = [],
  $log4j2_ensure                  = 'file',
  $logdir                         = '/var/log/elasticsearch',
  $logging_config                 = undef,
  $logging_file                   = undef,
  $logging_template               = undef,
  $logging_yml_ensure             = 'file',
  $manage_repo                    = false,
  $package_dir                    = $elasticsearch::params::package_dir,
  $package_dl_timeout             = 600,
  $package_name                   = $elasticsearch::params::package,
  $package_pin                    = true,
  $package_provider               = 'package',
  $package_url                    = undef,
  $pipelines                      = undef,
  $pipelines_hiera_merge          = false,
  $plugindir                      = $elasticsearch::params::plugindir,
  $plugins                        = undef,
  $plugins_hiera_merge            = false,
  $proxy_url                      = undef,
  $purge_configdir                = false,
  $purge_package_dir              = false,
  $purge_secrets                  = false,
  $repo_baseurl                   = undef,
  $repo_key_id                    = '46095ACC8548582C1A2699A9D27D666CD88E42B4',
  $repo_key_source                = 'https://artifacts.elastic.co/GPG-KEY-elasticsearch',
  $repo_priority                  = undef,
  $repo_proxy                     = undef,
  $repo_stage                     = false,
  $repo_version                   = undef,
  $restart_on_change              = $elasticsearch::params::restart_on_change,
  $restart_config_change          = $elasticsearch::restart_on_change,
  $restart_package_change         = $elasticsearch::restart_on_change,
  $restart_plugin_change          = $elasticsearch::restart_on_change,
  $roles                          = undef,
  $roles_hiera_merge              = false,
  $rolling_file_max_backup_index  = 1,
  $rolling_file_max_file_size     ='10MB',
  $scripts                        = undef,
  $scripts_hiera_merge            = false,
  $secrets                        = undef,
  $security_logging_content       = undef,
  $security_logging_source        = undef,
  $security_plugin                = undef,
  $service_provider               = 'init',
  $status                         = 'enabled',
  $system_key                     = undef,
  $templates                      = undef,
  $templates_hiera_merge          = false,
  $users                          = undef,
  $users_hiera_merge              = false,
  $validate_tls                   = true,
  $version                        = false,
) inherits elasticsearch::params {

  anchor {'elasticsearch::begin': }

  #### Validate parameters

  # ensure
  if ! ($ensure in [ 'present', 'absent' ]) {
    fail("\"${ensure}\" is not a valid ensure parameter value")
  }

  # autoupgrade
  validate_bool($autoupgrade)

  # service status
  if ! ($status in [ 'enabled', 'disabled', 'running', 'unmanaged' ]) {
    fail("\"${status}\" is not a valid status parameter value")
  }

  if ! ($file_rolling_type in [ 'dailyRollingFile', 'rollingFile']) {
    fail("\"${file_rolling_type}\" is not a valid type")
  }

  validate_array($jvm_options)
  validate_integer($rolling_file_max_backup_index)
  validate_string($daily_rolling_date_pattern)
  validate_string($rolling_file_max_file_size)

  # restart on change
  validate_bool(
    $restart_on_change,
    $restart_config_change,
    $restart_package_change,
    $restart_plugin_change
  )

  # purge conf dir
  validate_bool($purge_configdir)

  if is_array($elasticsearch::params::service_providers) {
    # Verify the service provider given is in the array
    if ! ($service_provider in $elasticsearch::params::service_providers) {
      fail("\"${service_provider}\" is not a valid provider for \"${::operatingsystem}\"")
    }
    $real_service_provider = $service_provider
  } else {
    # There is only one option so simply set it
    $real_service_provider = $elasticsearch::params::service_providers
  }

  if ($package_url != undef and $version != false) {
    fail('Unable to set the version number when using package_url option.')
  }

  if $ensure == 'present' {
    # validate config hash
    if ($config != undef) {
      validate_hash($config)
    }

    if ($logging_config != undef) {
      validate_hash($logging_config)
    }

    if ($secrets != undef) {
      validate_hash($secrets)
    }
  }

  # java install validation
  validate_bool($java_install)

  validate_bool(
    $datadir_instance_directories,
    $manage_repo,
    $package_pin
  )

  if ($manage_repo == true and $ensure == 'present') {
    if $repo_baseurl != undef {
      validate_string($repo_baseurl)
    } elsif $repo_version == undef {
      fail('Please fill in a repository version at $repo_version')
    } else {
      validate_string($repo_version)
    }
  }

  if ($version != false) {
    case $::osfamily {
      'RedHat', 'Linux', 'Suse': {
        if ($version =~ /.+-\d/) {
          $pkg_version = $version
        } else {
          $pkg_version = "${version}-1"
        }
      }
      default: {
        $pkg_version = $version
      }
    }
  }

  # Various parameters governing API access to Elasticsearch
  validate_string($api_protocol, $api_host)
  validate_bool($validate_tls)
  if $api_basic_auth_username { validate_string($api_basic_auth_username) }
  if $api_basic_auth_password { validate_string($api_basic_auth_password) }

  if ! is_integer($api_timeout) {
    fail("'${api_timeout}' is not an integer")
  }

  if ! is_integer($api_port) {
    fail("'${api_port}' is not an integer")
  }

  if $system_key != undef { validate_string($system_key) }

  #### Manage actions

  # package(s)
  class { 'elasticsearch::package': }

  # configuration
  class { 'elasticsearch::config': }

  # Hiera support for configuration hash
  validate_bool($config_hiera_merge)

  if $config_hiera_merge == true {
    $x_config = hiera_hash('elasticsearch::config', $config)
  } else {
    $x_config = $config
  }

  # Hiera support for indices
  validate_bool($indices_hiera_merge)

  if $indices_hiera_merge == true {
    $x_indices = hiera_hash('elasticsearch::indices', $::elasticsearch::indices)
  } else {
    $x_indices = $indices
  }

  if $x_indices {
    validate_hash($x_indices)
    create_resources('elasticsearch::index', $x_indices)
  }

  # Hiera support for instances
  validate_bool($instances_hiera_merge)

  if $instances_hiera_merge == true {
    $x_instances = hiera_hash('elasticsearch::instances', $::elasticsearch::instances)
  } else {
    $x_instances = $instances
  }

  if $x_instances {
    validate_hash($x_instances)
    create_resources('elasticsearch::instance', $x_instances)
  }

  # Hiera support for pipelines
  validate_bool($pipelines_hiera_merge)

  if $pipelines_hiera_merge == true {
    $x_pipelines = hiera_hash('elasticsearch::pipelines', $::elasticsearch::pipelines)
  } else {
    $x_pipelines = $pipelines
  }

  if $x_pipelines {
    validate_hash($x_pipelines)
    create_resources('elasticsearch::pipeline', $x_pipelines)
  }

  # Hiera support for plugins
  validate_bool($plugins_hiera_merge)

  if $plugins_hiera_merge == true {
    $x_plugins = hiera_hash('elasticsearch::plugins', $::elasticsearch::plugins)
  } else {
    $x_plugins = $plugins
  }

  if $x_plugins {
    validate_hash($x_plugins)
    create_resources('elasticsearch::plugin', $x_plugins)
  }

  # Hiera support for roles
  validate_bool($roles_hiera_merge)

  if $roles_hiera_merge == true {
    $x_roles = hiera_hash('elasticsearch::roles', $::elasticsearch::roles)
  } else {
    $x_roles = $roles
  }

  if $x_roles {
    validate_hash($x_roles)
    create_resources('elasticsearch::role', $x_roles)
  }

  # Hiera support for scripts
  validate_bool($scripts_hiera_merge)

  if $scripts_hiera_merge == true {
    $x_scripts = hiera_hash('elasticsearch::scripts', $::elasticsearch::scripts)
  } else {
    $x_scripts = $scripts
  }

  if $x_scripts {
    validate_hash($x_scripts)
    create_resources('elasticsearch::script', $x_scripts)
  }

  # Hiera support for templates
  validate_bool($templates_hiera_merge)

  if $templates_hiera_merge == true {
    $x_templates = hiera_hash('elasticsearch::templates', $::elasticsearch::templates)
  } else {
    $x_templates = $templates
  }

  if $x_templates {
    validate_hash($x_templates)
    create_resources('elasticsearch::template', $x_templates)
  }

  # Hiera support for users
  validate_bool($users_hiera_merge)

  if $users_hiera_merge == true {
    $x_users = hiera_hash('elasticsearch::users', $::elasticsearch::users)
  } else {
    $x_users = $users
  }

  if $x_users {
    validate_hash($x_users)
    create_resources('elasticsearch::user', $x_users)
  }

  if $java_install == true {
    # Install java
    class { '::java':
      package      => $java_package,
      distribution => 'jre',
    }

    # ensure we first install java, the package and then the rest
    Anchor['elasticsearch::begin']
    -> Class['::java']
    -> Class['elasticsearch::package']
  }

  if $package_pin {
    class { 'elasticsearch::package::pin':
      before => Class['elasticsearch::package'],
    }
  }

  if ($manage_repo == true) {

    if ($repo_stage == false) {
      # use anchor for ordering

      # Set up repositories
      class { 'elasticsearch::repo': }

      # Ensure that we set up the repositories before trying to install
      # the packages
      Anchor['elasticsearch::begin']
      -> Class['elasticsearch::repo']
      -> Class['elasticsearch::package']

    } else {
      # use staging for ordering

      if !(defined(Stage[$repo_stage])) {
        stage { $repo_stage:  before => Stage['main'] }
      }

      class { 'elasticsearch::repo':
        stage => $repo_stage,
      }
    }

  }

  #### Manage relationships
  #
  # Note that many of these overly verbose declarations work around
  # https://tickets.puppetlabs.com/browse/PUP-1410
  # which means clean arrow order chaining won't work if someone, say,
  # doesn't declare any plugins.
  #
  # forgive me for what you're about to see

  if $ensure == 'present' {

    # Anchor, installation, and configuration
    Anchor['elasticsearch::begin']
    -> Class['elasticsearch::package']
    -> Class['elasticsearch::config']

    # Top-level ordering bindings for resources.
    Class['elasticsearch::config']
    -> Elasticsearch::Plugin <| ensure == 'present' or ensure == 'installed' |>
    Elasticsearch::Plugin <| ensure == 'absent' |>
    -> Class['elasticsearch::config']
    Class['elasticsearch::config']
    -> Elasticsearch::Instance <| |>
    Class['elasticsearch::config']
    -> Elasticsearch::User <| |>
    Class['elasticsearch::config']
    -> Elasticsearch::Role <| |>
    Class['elasticsearch::config']
    -> Elasticsearch::Template <| |>
    Class['elasticsearch::config']
    -> Elasticsearch::Pipeline <| |>
    Class['elasticsearch::config']
    -> Elasticsearch::Index <| |>

  } else {

    # Main anchor and included classes
    Anchor['elasticsearch::begin']
    -> Class['elasticsearch::config']
    -> Class['elasticsearch::package']

    # Top-level ordering bindings for resources.
    Anchor['elasticsearch::begin']
    -> Elasticsearch::Plugin <| |>
    -> Class['elasticsearch::config']
    Anchor['elasticsearch::begin']
    -> Elasticsearch::Instance <| |>
    -> Class['elasticsearch::config']
    Anchor['elasticsearch::begin']
    -> Elasticsearch::User <| |>
    -> Class['elasticsearch::config']
    Anchor['elasticsearch::begin']
    -> Elasticsearch::Role <| |>
    -> Class['elasticsearch::config']
    Anchor['elasticsearch::begin']
    -> Elasticsearch::Template <| |>
    -> Class['elasticsearch::config']
    Anchor['elasticsearch::begin']
    -> Elasticsearch::Pipeline <| |>
    -> Class['elasticsearch::config']
    Anchor['elasticsearch::begin']
    -> Elasticsearch::Index <| |>
    -> Class['elasticsearch::config']

  }

  # Install plugins before managing instances or users/roles
  Elasticsearch::Plugin <| ensure == 'present' or ensure == 'installed' |>
  -> Elasticsearch::Instance <| |>
  Elasticsearch::Plugin <| ensure == 'present' or ensure == 'installed' |>
  -> Elasticsearch::User <| |>
  Elasticsearch::Plugin <| ensure == 'present' or ensure == 'installed' |>
  -> Elasticsearch::Role <| |>

  # Remove plugins after managing users/roles
  Elasticsearch::User <| |>
  -> Elasticsearch::Plugin <| ensure == 'absent' |>
  Elasticsearch::Role <| |>
  -> Elasticsearch::Plugin <| ensure == 'absent' |>

  # Ensure roles are defined before managing users that reference roles
  Elasticsearch::Role <| |>
  -> Elasticsearch::User <| ensure == 'present' |>
  # Ensure users are removed before referenced roles are managed
  Elasticsearch::User <| ensure == 'absent' |>
  -> Elasticsearch::Role <| |>

  # Ensure users and roles are managed before calling out to REST resources
  Elasticsearch::Role <| |>
  -> Elasticsearch::Template <| |>
  Elasticsearch::User <| |>
  -> Elasticsearch::Template <| |>
  Elasticsearch::Role <| |>
  -> Elasticsearch::Pipeline <| |>
  Elasticsearch::User <| |>
  -> Elasticsearch::Pipeline <| |>
  Elasticsearch::Role <| |>
  -> Elasticsearch::Index <| |>
  Elasticsearch::User <| |>
  -> Elasticsearch::Index <| |>

  # Manage users/roles before instances (req'd to keep dir in sync)
  Elasticsearch::Role <| |>
  -> Elasticsearch::Instance <| |>
  Elasticsearch::User <| |>
  -> Elasticsearch::Instance <| |>

  # Ensure instances are started before managing REST resources
  Elasticsearch::Instance <| ensure == 'present' |>
  -> Elasticsearch::Template <| |>
  Elasticsearch::Instance <| ensure == 'present' |>
  -> Elasticsearch::Pipeline <| |>
  Elasticsearch::Instance <| ensure == 'present' |>
  -> Elasticsearch::Index <| |>
  # Ensure instances are stopped after managing REST resources
  Elasticsearch::Template <| |>
  -> Elasticsearch::Instance <| ensure == 'absent' |>
  Elasticsearch::Pipeline <| |>
  -> Elasticsearch::Instance <| ensure == 'absent' |>
  Elasticsearch::Index <| |>
  -> Elasticsearch::Instance <| ensure == 'absent' |>
}