Defined Type: cassandra::instance

Defined in:
modules/cassandra/manifests/instance.pp

Overview

Define: cassandra::instance

Installs and configures a Cassandra server instance

Usage

cassandra::instance { 'instance-name': instances => ... }

Parameters

See cassandra class for parameters already defined there.

[title] The name of this cassandra instance. The name "default" can be used as instance name to obtain cassandra's standard behaviour with a single instance.

[num_tokens] Number of tokens randomly assigned to this node on the ring. Default: 256

[authenticator] Authentication backend, implementing IAuthenticator; used to identify users. If false, AllowAllAuthenticator will be used. If true, PasswordAuthenticator will be used. Else, the value provided will be used. Default: true

[authorizor] Authorization backend, implementing IAuthorizer; used to limit access/provide permissions. If false, AllowAllAuthorizer will be used. If true, CassandraAuthorizer will be used. Else, the value provided will be used. Default: true

[permissions_validity_in_ms] Validity period for permissions cache (fetching permissions can be an expensive operation depending on the authorizer, CassandraAuthorizer is one example). Will be disabled automatically for AllowAllAuthorizer. Defaults to 2000, set to 0 to disable.

[data_directory_base] The base directory for cassandra data if we use default instance. In case of multi-instances this directory is generated based on the instance name. Default: /var/lib/cassandra

[data_file_directories] Array of directories where Cassandra should store data on disk. This module will not set up partitions or RAID, so make sure You have these directories configured as you like and mounted before you apply this module. Default: [/var/lib/cassandra/data]

[local_system_data_file_directory] Directory where Cassandra should store local system keyspaces. In a JBOD configuration, this should be configured to use a RAID array so that local system state is not corrupted by the failure of any one disk. Default: undef

[commitlog_directory] Directory where Cassandra should store its commit log. Default: /var/lib/cassandra/commitlog

[hints_directory] Directory where Cassandra stores hints (Cassandra >= 3.0) Default: /var/lib/cassandra/data/hints

[disk_failure_policy] Policy for data disk failure. Should be one of:

stop_paranoid, die, stop, best_effort, or ignore.
Default: stop

[row_cache_size_in_mb] Enable a small cache by default. Default: 200

[saved_caches_directory] Directory where Cassandra should store saved caches. Default: /var/lib/cassandra/saved_caches

[users] Users to enable on the instance - grants must exist in templates/users Default: []

[cassandra_passwords] A mapping of user->passwords from secrets Default: undef

[concurrent_reads] Number of allowed concurrent reads. Default: 32

[concurrent_writes] Number of allowed concurrent writes. Impacts peak memory usage. Default: 32

[concurrent_counter_writes] Number of allowed concurrent counter writes. Default: 32

[trickle_fsync] Whether or not to enable trickle_fsync. Default: true

[trickle_fsync_interval_in_kb] Interval (in kilobytes) when sequential writing to fsync(), forcing the operating system to flush the dirty buffers. Default: 30240

[storage_port] TCP port for cluster communication Default: 7000

[broadcast_address] IP address to broadcast to other Cassandra nodes. Default: undef (uses $listen _address)

[start_native_transport] Whether to start the native transport server. Default: true

[rpc_address] IP address to bind the Thrift RPC service and native transport server. Default: $::ipaddress

[rpc_port] Port for Thrift to listen for clients on (target_version <= 3.x). Default: 9160

[rpc_server_type] RPC server type, either 'sync' or 'hsha' (target_version <= 3.x). Default: sync

[incremental_backups] If true, Cassandra will create incremental hardlink backups. Default: false

[snapshot_before_compaction] Whether or not to take a snapshot before each compaction. Default: false

[auto_snapshot] Whether or not a snapshot is taken of the data before keyspace truncation or dropping of column families. Default: true

[compaction_throughput_mb_per_sec] Throttles compaction to the given total throughput across the entire system. Default: 16

[concurrent_compactors] Number of simultaneous compactions to allow. Default: 1

[streaming_socket_timeout_in_ms] Number of milliseconds required to time out streaming connections. Default: 0 (disabled)

[endpoint_snitch] Set this to a class that implements IEndpointSnitch. Default: GossipingPropertyFileSnitch

[internode_compression] Controls whether traffic between nodes is compressed. Should be one of: all, dc, or none Default: all

[max_heap_size] Value for -Xms and -Xmx to pass to the JVM. Example: '8g' Default: undef

[heap_newsize] Value for -Xmn to pass to the JVM. Example: '1200m' Default: undef

[jmx_port] Port to listen for JMX queries. Default: 7199

[key_cache_size_in_mb] Maximum size of the key cache in memory. Default: empty (aka "auto" (min(5% of heap (in MB), 100MB)))

[internode_encryption] What level of inter node encryption to enable Default: none

[server_encryption_optional] Controls whether server encryption is optional. This should only be true when encryption is not enabled (i.e. internode_encryption: none), or during a transitional period. Default: false

[client_encryption_enabled] Enable client-side encryption Default: false

[client_encryption_optional] Controls whether client encryption is optional (only relevant when encryption is enabled, see: client_encryption_enabled) Default: false

[auto_bootstrap] Control whether new nodes joining the cluster will get data they own. Default: true

[auto_apply_grants] Toggle whether changes to grants files are applied automatically Default: false

[nodetool_path] Complete path to nodetool command. Default: /usr/bin/nodetool

[legacy_ssl_storage_port_enabled] Whether or not to enable the legacy SSL storage port. Must be enabled during upgrades from 3.x to 4.x; Should be disabled after upgrade to 4.x. Default: false

Parameters:

  • cluster_name (Optional[String]) (defaults to: undef)
  • memory_allocator (Optional[String]) (defaults to: undef)
  • listen_address (Optional[Stdlib::IP::Address]) (defaults to: undef)
  • tls_cluster_name (Optional[String]) (defaults to: undef)
  • default_applications (Optional[String]) (defaults to: undef)
  • native_transport_port (Optional[Stdlib::Port]) (defaults to: undef)
  • target_version (Optional[String]) (defaults to: undef)
  • seeds (Optional[Array[Stdlib::Host, 1]]) (defaults to: undef)
  • dc (Optional[String]) (defaults to: undef)
  • rack (Optional[String]) (defaults to: undef)
  • additional_jvm_opts (Optional[Array[String]]) (defaults to: undef)
  • extra_classpath (Optional[Array[String]]) (defaults to: undef)
  • logstash_host (Optional[Stdlib::Host]) (defaults to: undef)
  • logstash_port (Optional[Stdlib::Port]) (defaults to: undef)
  • start_rpc (Optional[Boolean]) (defaults to: undef)
  • super_username (Optional[String]) (defaults to: undef)
  • super_password (Optional[String]) (defaults to: undef)
  • tls_use_pki (Boolean) (defaults to: false)
  • tls_use_pki_truststore (Boolean) (defaults to: false)
  • tls_use_pki_keep_old_ca (Boolean) (defaults to: false)
  • tls_keystore_password (Optional[String]) (defaults to: undef)
  • storage_compatibility_mode (Optional[String]) (defaults to: undef)
  • config_directory (Stdlib::Unixpath) (defaults to: "/etc/cassandra-${title}")
  • service_name (String) (defaults to: "cassandra-${title}")
  • tls_hostname (String) (defaults to: "${facts['networking']['hostname']}-${title}")
  • pid_file (Stdlib::Unixpath) (defaults to: "/var/run/cassandra/cassandra-${title}.pid")
  • instance_id (String) (defaults to: "${facts['networking']['hostname']}-${title}")
  • jmx_port (Optional[Stdlib::Port]) (defaults to: undef)
  • data_directory_base (Stdlib::Unixpath) (defaults to: "/srv/cassandra-${title}")
  • data_directories (Array[String]) (defaults to: ['data'])
  • data_file_directories (Array[Stdlib::Unixpath]) (defaults to: [])
  • commitlog_directory (Stdlib::Unixpath) (defaults to: "/srv/cassandra-${title}/commitlog")
  • hints_directory (Stdlib::Unixpath) (defaults to: "/srv/cassandra-${title}/data/hints")
  • heapdump_directory (Stdlib::Unixpath) (defaults to: "/srv/cassandra-${title}")
  • saved_caches_directory (Stdlib::Unixpath) (defaults to: "/srv/cassandra-${title}/saved_caches")
  • users (Array[String]) (defaults to: [])
  • cassandra_passwords (Hash[String, String]) (defaults to: {})
  • nodetool_path (Stdlib::Unixpath) (defaults to: "/usr/local/bin/nodetool-${title}")
  • num_tokens (Integer) (defaults to: 256)
  • authenticator (Boolean) (defaults to: true)
  • authorizor (Boolean) (defaults to: true)
  • permissions_validity_in_ms (Integer) (defaults to: 2000)
  • disk_failure_policy (Enum['stop', 'best_effort', 'ignore']) (defaults to: 'stop')
  • row_cache_size_in_mb (Integer) (defaults to: 200)
  • concurrent_reads (Integer) (defaults to: 32)
  • concurrent_writes (Integer) (defaults to: 32)
  • concurrent_counter_writes (Integer) (defaults to: 32)
  • trickle_fsync (Boolean) (defaults to: true)
  • trickle_fsync_interval_in_kb (Integer) (defaults to: 30240)
  • storage_port (Stdlib::Port) (defaults to: 7000)
  • broadcast_address (Optional[Stdlib::IP::Address]) (defaults to: undef)
  • start_native_transport (Boolean) (defaults to: true)
  • rpc_address (Optional[Stdlib::IP::Address]) (defaults to: undef)
  • rpc_port (Stdlib::Port) (defaults to: 9160)
  • rpc_server_type (Enum['hsha', 'sync', 'async']) (defaults to: 'sync')
  • incremental_backups (Boolean) (defaults to: false)
  • snapshot_before_compaction (Boolean) (defaults to: false)
  • auto_snapshot (Boolean) (defaults to: true)
  • compaction_throughput_mb_per_sec (Integer) (defaults to: 16)
  • concurrent_compactors (Integer) (defaults to: 1)
  • streaming_socket_timeout_in_ms (Integer) (defaults to: 0)
  • endpoint_snitch (String) (defaults to: 'GossipingPropertyFileSnitch')
  • internode_compression (Enum['all', 'dc', 'none']) (defaults to: 'all')
  • max_heap_size (Optional[String]) (defaults to: undef)
  • heap_newsize (Optional[String]) (defaults to: undef)
  • key_cache_size_in_mb (Integer) (defaults to: 400)
  • internode_encryption (Enum['all','dc', 'none']) (defaults to: 'none')
  • server_encryption_optional (Boolean) (defaults to: false)
  • client_encryption_enabled (Boolean) (defaults to: false)
  • client_encryption_optional (Boolean) (defaults to: false)
  • auto_bootstrap (Boolean) (defaults to: true)
  • monitor_enabled (Boolean) (defaults to: true)
  • auto_apply_grants (Boolean) (defaults to: false)
  • legacy_ssl_storage_port_enabled (Boolean) (defaults to: false)
  • local_system_data_file_directory (Optional[Stdlib::Unixpath]) (defaults to: undef)


218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
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
# File 'modules/cassandra/manifests/instance.pp', line 218

define cassandra::instance (
    # the following parameters are injected by the main cassandra class
    Optional[String]                 $cluster_name            = undef,
    Optional[String]                 $memory_allocator        = undef,
    Optional[Stdlib::IP::Address]    $listen_address          = undef,
    Optional[String]                 $tls_cluster_name        = undef,
    Optional[String]                 $default_applications    = undef,
    Optional[Stdlib::Port]           $native_transport_port   = undef,
    Optional[String]                 $target_version          = undef,
    Optional[Array[Stdlib::Host, 1]] $seeds                   = undef,
    Optional[String]                 $dc                      = undef,
    Optional[String]                 $rack                    = undef,
    Optional[Array[String]]          $additional_jvm_opts     = undef,
    Optional[Array[String]]          $extra_classpath         = undef,
    Optional[Stdlib::Host]           $logstash_host           = undef,
    Optional[Stdlib::Port]           $logstash_port           = undef,
    Optional[Boolean]                $start_rpc               = undef,
    Optional[String]                 $super_username          = undef,
    Optional[String]                 $super_password          = undef,
    Boolean                          $tls_use_pki             = false,
    Boolean                          $tls_use_pki_truststore  = false,
    Boolean                          $tls_use_pki_keep_old_ca = false,
    Optional[String]                 $tls_keystore_password   = undef,
    Optional[String]                 $storage_compatibility_mode = undef,

    # the following parameters need specific default values for single instance
    Stdlib::Unixpath        $config_directory       = "/etc/cassandra-${title}",
    String                  $service_name           = "cassandra-${title}",
    String                  $tls_hostname           = "${facts['networking']['hostname']}-${title}",
    Stdlib::Unixpath        $pid_file               = "/var/run/cassandra/cassandra-${title}.pid",
    String                  $instance_id            = "${facts['networking']['hostname']}-${title}",
    Optional[Stdlib::Port]  $jmx_port               = undef,
    Stdlib::Unixpath        $data_directory_base    = "/srv/cassandra-${title}",
    Array[String]           $data_directories       = ['data'],
    Array[Stdlib::Unixpath] $data_file_directories  = [],
    Stdlib::Unixpath        $commitlog_directory    = "/srv/cassandra-${title}/commitlog",
    Stdlib::Unixpath        $hints_directory        = "/srv/cassandra-${title}/data/hints",
    Stdlib::Unixpath        $heapdump_directory     = "/srv/cassandra-${title}",
    Stdlib::Unixpath        $saved_caches_directory = "/srv/cassandra-${title}/saved_caches",
    Array[String]           $users                  = [],
    Hash[String, String]    $cassandra_passwords    = {},
    Stdlib::Unixpath        $nodetool_path          = "/usr/local/bin/nodetool-${title}",

    # the following parameters have defaults that are sane both for single-
    # and multi-instances
    Integer                               $num_tokens                       = 256,
    Boolean                               $authenticator                    = true,
    Boolean                               $authorizor                       = true,
    Integer                               $permissions_validity_in_ms       = 2000,
    Enum['stop', 'best_effort', 'ignore'] $disk_failure_policy              = 'stop',
    Integer                               $row_cache_size_in_mb             = 200,
    Integer                               $concurrent_reads                 = 32,
    Integer                               $concurrent_writes                = 32,
    Integer                               $concurrent_counter_writes        = 32,
    Boolean                               $trickle_fsync                    = true,
    Integer                               $trickle_fsync_interval_in_kb     = 30240,
    Stdlib::Port                          $storage_port                     = 7000,
    Optional[Stdlib::IP::Address]         $broadcast_address                = undef,
    Boolean                               $start_native_transport           = true,
    Optional[Stdlib::IP::Address]         $rpc_address                      = undef,
    Stdlib::Port                          $rpc_port                         = 9160,
    Enum['hsha', 'sync', 'async']         $rpc_server_type                  = 'sync',
    Boolean                               $incremental_backups              = false,
    Boolean                               $snapshot_before_compaction       = false,
    Boolean                               $auto_snapshot                    = true,
    Integer                               $compaction_throughput_mb_per_sec = 16,
    Integer                               $concurrent_compactors            = 1,
    Integer                               $streaming_socket_timeout_in_ms   = 0,
    String                                $endpoint_snitch                  = 'GossipingPropertyFileSnitch',
    Enum['all', 'dc', 'none']             $internode_compression            = 'all',
    Optional[String]                      $max_heap_size                    = undef,
    Optional[String]                      $heap_newsize                     = undef,
    Integer                               $key_cache_size_in_mb             = 400,
    Enum['all','dc', 'none']              $internode_encryption             = 'none',
    Boolean                               $server_encryption_optional       = false,
    Boolean                               $client_encryption_enabled        = false,
    Boolean                               $client_encryption_optional       = false,
    Boolean                               $auto_bootstrap                   = true,
    Boolean                               $monitor_enabled                  = true,
    Boolean                               $auto_apply_grants                = false,
    Boolean                               $legacy_ssl_storage_port_enabled  = false,
    Optional[Stdlib::Unixpath]            $local_system_data_file_directory = undef,
) {

    $instance_data_file_directories = $data_file_directories.empty? {
        true => prefix($data_directories, "${data_directory_base}/"),
        default => $data_file_directories,
    }

    # Choose real authenticator and authorizor values
    $authenticator_value = $authenticator ? {
        true    => 'PasswordAuthenticator',
        false   => 'AllowAllAuthenticator',
        default => $authenticator,
    }
    $authorizor_value = $authorizor ? {
        true    => 'CassandraAuthorizer',
        false   => 'AllowAllAuthorizer',
        default => $authorizor,
    }

    $instance_name = $title

    # Default jmx port; only works with 1-letter instnaces
    $default_jmx_port     = 7189 + Integer(inline_template("<%= @title.ord - 'a'.ord %>"))

    # Relevant values, choosing convention over configuration
    $instance_jmx_port    = pick($jmx_port, $default_jmx_port)

    $instance_rpc_address = pick($rpc_address, $listen_address)

    # Add the IP address if not present
    if $instance_rpc_address != $facts['networking']['ip'] {
        interface::alias { "cassandra-${instance_name}":
            ipv4      => $instance_rpc_address,
        }
    }

    file { $config_directory:
        ensure  => directory,
        owner   => 'root',
        group   => 'root',
        mode    => '0755',
        require => Package['cassandra'],
    }

    file { $data_directory_base:
        ensure  => directory,
        owner   => 'cassandra',
        group   => 'cassandra',
        mode    => '0750',
        require => Package['cassandra'],
    }

    # Storage directories are an array of arbitrary, fully-qualified paths;
    # Since we cannot guarantee a common base path, ensure will not work.
    flatten([$instance_data_file_directories, $commitlog_directory, $saved_caches_directory, $hints_directory]).each | $data_dir | {
        exec { "install-${data_dir}":
            command => "install -o cassandra -g cassandra -m 750 -d ${data_dir}",
            path    => '/usr/bin/:/bin/',
            before  => Systemd::Service[$service_name],
            creates => $data_dir,
        }
    }

    # The storage directory for local keyspaces does not have a
    # default value, so must be handled separately.
    if $local_system_data_file_directory {
        exec { "install-${local_system_data_file_directory}":
            command => "install -o cassandra -g cassandra -m 750 -d ${local_system_data_file_directory}",
            path    => '/usr/bin/:/bin/',
            before  => Systemd::Service[$service_name],
            creates => $local_system_data_file_directory,
        }
    }

    file { "${config_directory}/cassandra-env.sh":
        ensure  => present,
        content => template("${module_name}/cassandra-env.sh-${target_version}.erb"),
        owner   => 'cassandra',
        group   => 'cassandra',
        mode    => '0444',
    }

    file { "${config_directory}/cassandra-rackdc.properties":
        ensure  => present,
        content => template("${module_name}/cassandra-rackdc.properties.erb"),
        owner   => 'cassandra',
        group   => 'cassandra',
        mode    => '0444',
    }

    file { "${config_directory}/logback.xml":
        ensure  => present,
        content => template("${module_name}/logback.xml-${target_version}.erb"),
        owner   => 'cassandra',
        group   => 'cassandra',
        mode    => '0444',
    }

    file { "${config_directory}/logback-tools.xml":
        ensure => present,
        source => "puppet:///modules/${module_name}/logback-tools.xml-${target_version}",
        links  => follow,
        owner  => 'cassandra',
        group  => 'cassandra',
        mode   => '0444',
    }

    file { "${config_directory}/cqlshrc":
        content => template("${module_name}/cqlshrc-${target_version}.erb"),
        owner   => 'root',
        group   => 'root',
        mode    => '0400',
        require => Package['cassandra'],
    }

    file { "${config_directory}/prometheus_jmx_exporter.yaml":
        ensure  => present,
        source  => "puppet:///modules/${module_name}/prometheus_jmx_exporter-${target_version}.yaml",
        owner   => 'cassandra',
        group   => 'cassandra',
        mode    => '0400',
        links   => follow,
        require => Package['cassandra'],
    }

    stdlib::ensure_packages(['prometheus-jmx-exporter'])

    $prometheus_target = $instance_name ? {
        'default' => $facts['networking']['hostname'],
        default   => "${facts['networking']['hostname']}-${instance_name}",
    }
    prometheus::jmx_exporter_instance { $prometheus_target:
        hostname => $prometheus_target,
        port     => 7800,
    }

    $users.each |String $username| {
        if $auto_apply_grants {
            exec { "load_${username}_grants_${title}":
                command     => "/usr/local/bin/cassandra_validate_grants ${config_directory}/user_${username}.cql && /usr/bin/c-cqlsh ${title} -f ${config_directory}/user_${username}.cql",
                subscribe   => File["${config_directory}/user_${username}.cql"],
                refreshonly => true,
            }
        }

        $application_password = $cassandra_passwords[$username]
        file { "${config_directory}/user_${username}.cql":
            content => template("${module_name}/users/${username}.cql.erb"),
            owner   => 'root',
            group   => 'root',
            mode    => '0400',
            require => Package['cassandra'],
        }
    }

    if $tls_cluster_name {
        if $tls_use_pki_truststore {
            $tls_truststore_location = profile::base::certificates::get_trusted_ca_jks_path()
            $tls_truststore_password = profile::base::certificates::get_trusted_ca_jks_password()
            # If the PKI trustore bundle is composed using the current
            # rootCa.crt file (via profile::base::certificates) we need
            # to keep it around in the Puppet Catalog for consistency.
            # We could use a more elaborate scheme but it is just a setting
            # to allow us to rollout PKI certificates more easily.
            # TODO: remove this once we have deployed PKI everywhere.
            if $tls_use_pki_keep_old_ca {
                file { "${config_directory}/tls/rootCa.crt":
                    content => secret("cassandra/${tls_cluster_name}/rootCa.crt"),
                    owner   => 'cassandra',
                    group   => 'cassandra',
                    mode    => '0400',
                }
            }
        } else {
            $tls_truststore_location = "${config_directory}/tls/server.trust"
            $tls_truststore_password = undef

            file { $tls_truststore_location:
                content => secret("cassandra/${tls_cluster_name}/truststore"),
                owner   => 'cassandra',
                group   => 'cassandra',
                mode    => '0400',
            }

            file { "${config_directory}/tls/rootCa.crt":
                content => secret("cassandra/${tls_cluster_name}/rootCa.crt"),
                owner   => 'cassandra',
                group   => 'cassandra',
                mode    => '0400',
            }
        }
        if $tls_use_pki {
            $tls_dir = "${config_directory}/tls"
            $instance_fqdn = "${tls_hostname}.${::site}.wmnet"
            $tls_files = profile::pki::get_cert('cassandra', $instance_fqdn, {
                'outdir' => $tls_dir,
                'owner'  => 'cassandra',
                'group'  => 'cassandra',
                'mode'   => '0400',
                'hosts'  => ['cassandra', $facts['networking']['fqdn']],
                notify   => Sslcert::X509_to_pkcs12["cassandra_keystore_${tls_hostname}"],
                }
            )

            $tls_keystore_location = "${tls_dir}/server.key"
            sslcert::x509_to_pkcs12 { "cassandra_keystore_${tls_hostname}" :
                owner       => 'cassandra',
                group       => 'cassandra',
                public_key  => $tls_files['chained'],
                private_key => $tls_files['key'],
                certfile    => $tls_files['ca'],
                outfile     => $tls_keystore_location,
                password    => $tls_keystore_password,
            }
        } else {
            file { "${config_directory}/tls":
                ensure  => directory,
                owner   => 'cassandra',
                group   => 'cassandra',
                mode    => '0400',
                require => Package['cassandra'],
            }

            file { "${config_directory}/tls/server.key":
                content   => secret("cassandra/${tls_cluster_name}/${tls_hostname}/${tls_hostname}.kst"),
                owner     => 'cassandra',
                group     => 'cassandra',
                mode      => '0400',
                show_diff => false,
            }
        }
    }

    file { "${config_directory}/cassandra.yaml":
        ensure  => present,
        content => template("${module_name}/cassandra.yaml-${target_version}.erb"),
        owner   => 'cassandra',
        group   => 'cassandra',
        mode    => '0444',
    }

    if $instance_name != 'default' {
        file { $nodetool_path:
            ensure  => link,
            target  => '/usr/local/bin/nodetool-instance',
            require => File['/usr/local/bin/nodetool-instance'],
        }
    } else {
        file { '/usr/local/bin/nodetool':
            ensure => present,
            source => "puppet:///modules/${module_name}/nodetool",
            owner  => 'cassandra',
            group  => 'cassandra',
            mode   => '0755',
        }
    }

    if $instance_name != 'default' {
        file { "/usr/local/bin/sstableutil-${title}":
            ensure  => link,
            target  => '/usr/local/bin/sstable-util-instance',
            require => File['/usr/local/bin/sstable-util-instance'],
        }
    }

    if $instance_name != 'default' {
        file { "/usr/local/bin/cqlsh-${instance_name}":
            ensure  => link,
            target  => '/usr/bin/cqlsh-instance',
            require => Package['cassandra-tools-wmf'],
        }
    }

    file { "/etc/cassandra-instances.d/${tls_hostname}.yaml":
        content => template("${module_name}/instance.yaml.erb"),
        owner   => 'cassandra',
        group   => 'cassandra',
        mode    => '0444',
    }

    # This is becoming brittle; jvm.options was introduced in v3, in v4 we now
    # have jvm.options + JVM-specific add-ons (see below).
    if $target_version == '3.x' {
        file { "${config_directory}/jvm.options":
            ensure  => present,
            content => template("${module_name}/jvm.options-${target_version}.erb"),
            owner   => 'cassandra',
            group   => 'cassandra',
            mode    => '0444',
        }
    }

    # JVM17 is Cassandra >= 5.x only.
    if ($target_version in ['5.x']) {
        file { "${config_directory}/jvm17-server.options":
            ensure  => present,
            content => template("${module_name}/jvm17-server.options-${target_version}.erb"),
            owner   => 'cassandra',
            group   => 'cassandra',
            mode    => '0444',
        }
    }

    if ($target_version in ['4.x', '5.x', 'dev']) {
        file { "${config_directory}/jvm-server.options":
            ensure  => present,
            content => template("${module_name}/jvm-server.options-${target_version}.erb"),
            owner   => 'cassandra',
            group   => 'cassandra',
            mode    => '0444',
        }

        file { "${config_directory}/jvm11-server.options":
            ensure  => present,
            content => template("${module_name}/jvm11-server.options-${target_version}.erb"),
            owner   => 'cassandra',
            group   => 'cassandra',
            mode    => '0444',
        }

        # Install links (where necessary) to package-installed configs
        if $instance_name != 'default' {
            file { "${config_directory}/jvm-clients.options":
                ensure => link,
                target => '/etc/cassandra/jvm-clients.options',
                force  => true,
            }

            file { "${config_directory}/jvm11-clients.options":
                ensure => link,
                target => '/etc/cassandra/jvm11-clients.options',
                force  => true,
            }

            if ($target_version in ['5.x']) {
                file { "${config_directory}/jvm17-clients.options":
                    ensure => link,
                    target => '/etc/cassandra/jvm17-clients.options',
                    force  => true,
                }
            }
        }

        # The credentials file pairs with cqlshrc on Cassandra versions >= 4.1
        file { "${config_directory}/credentials":
            content => template("${module_name}/credentials-${target_version}.erb"),
            owner   => 'root',
            group   => 'root',
            mode    => '0400',
        }
    }

    if ($target_version in ['3.x', '4.x', '5.x', 'dev']) {
        file { "${config_directory}/hotspot_compiler":
            ensure => present,
            source => "puppet:///modules/${module_name}/hotspot_compiler-${target_version}",
            links  => follow,
            owner  => 'cassandra',
            group  => 'cassandra',
            mode   => '0444',
        }

        file { "${config_directory}/commitlog_archiving.properties":
            ensure => present,
            source => "puppet:///modules/${module_name}/commitlog_archiving.properties-${target_version}",
            links  => follow,
            owner  => 'cassandra',
            group  => 'cassandra',
            mode   => '0444',
        }
    }

    systemd::service { $service_name:
        ensure  => present,
        content => systemd_template('cassandra'),
        require => [
            File["${config_directory}/cassandra-env.sh"],
            File["${config_directory}/cassandra.yaml"],
            File["${config_directory}/cassandra-rackdc.properties"],
        ],
    }
}