Puppet Class: patroni

Defined in:
manifests/init.pp

Summary

Manages a Patroni instance

Overview

Parameters:

  • scope (String[1])

    Refer to Patroni Global ‘scope` setting

  • namespace (String[1]) (defaults to: '/service/')

    Refer to Patroni Global ‘namespace` setting

  • hostname (String) (defaults to: $facts['networking']['hostname'])

    Refer to Patroni Global ‘name` setting

  • dcs_loop_wait (Integer) (defaults to: 10)

    Refer to Patroni Dynamic Configuration Settings ‘loop_wait` setting

  • dcs_ttl (Integer) (defaults to: 30)

    Refer to Patroni Dynamic Configuration Settings ‘ttl` setting

  • dcs_retry_timeout (Integer) (defaults to: 10)

    Refer to Patroni Dynamic Configuration Settings ‘retry_timeout` setting

  • dcs_maximum_lag_on_failover (Integer) (defaults to: 1048576)

    Refer to Patroni Dynamic Configuration Settings ‘maximum_lag_on_failover` setting

  • dcs_master_start_timeout (Integer) (defaults to: 300)

    Refer to Patroni Dynamic Configuration Settings ‘master_start_timeout` setting

  • dcs_synchronous_mode (Boolean) (defaults to: false)

    Refer to Patroni Dynamic Configuration Settings ‘synchronous_mode` setting

  • dcs_synchronous_mode_strict (Boolean) (defaults to: false)

    Refer to Patroni Dynamic Configuration Settings ‘synchronous_mode_strict` setting

  • dcs_postgresql_use_pg_rewind (Boolean) (defaults to: true)

    Refer to Patroni Dynamic Configuration Settings ‘postgresql_use_pg_rewind` setting

  • dcs_postgresql_use_slots (Boolean) (defaults to: true)

    Refer to Patroni Dynamic Configuration Settings ‘postgresql_use_slots` setting

  • dcs_postgresql_recovery_conf (Hash) (defaults to: {})

    Refer to Patroni Dynamic Configuration Settings ‘postgresql_recovery_conf` setting

  • dcs_postgresql_parameters (Hash) (defaults to: {})

    Refer to Patroni Dynamic Configuration Settings ‘postgresql_parameters` setting

  • bootstrap_method (String[1]) (defaults to: 'initdb')

    Refer to Bootstrap configuration settings ‘method` setting

  • initdb_data_checksums (Boolean) (defaults to: true)

    Refer to Bootstrap configuration settings ‘data-checksums` setting

  • initdb_encoding (String) (defaults to: 'UTF8')

    Refer to Bootstrap configuration settings ‘encoding` setting

  • initdb_locale (String) (defaults to: 'en_US.utf8')

    Refer to Bootstrap configuration settings ‘locale` setting

  • bootstrap_pg_hba (Array[String]) (defaults to: [ 'host all all 0.0.0.0/0 md5', 'host replication rep_user 0.0.0.0/0 md5', ])

    Refer to Bootstrap configuration settings ‘pg_hba` setting

  • bootstrap_users (Hash) (defaults to: {})

    Refer to Bootstrap configuration settings ‘users` setting

  • bootstrap_post_bootstrap (Variant[Undef,String]) (defaults to: undef)

    Refer to Bootstrap configuration settings ‘post_bootstrap` setting

  • bootstrap_post_init (Variant[Undef,String]) (defaults to: undef)

    Refer to Bootstrap configuration settings ‘post_init` setting

  • superuser_username (String) (defaults to: 'postgres')

    Refer to PostgreSQL configuration settings superuser username

  • superuser_password (String) (defaults to: 'changeme')

    Refer to PostgreSQL configuration settings superuser password

  • replication_username (String) (defaults to: 'rep_user')

    Refer to PostgreSQL configuration settings replication username

  • replication_password (String) (defaults to: 'changeme')

    Refer to PostgreSQL configuration settings replication password

  • callback_on_reload (Variant[Undef,String]) (defaults to: undef)

    Refer to PostgreSQL configuration settings callbacks ‘on_reload`

  • callback_on_restart (Variant[Undef,String]) (defaults to: undef)

    Refer to PostgreSQL configuration settings callbacks ‘on_restart`

  • callback_on_role_change (Variant[Undef,String]) (defaults to: undef)

    Refer to PostgreSQL configuration settings callbacks ‘on_role_change`

  • callback_on_start (Variant[Undef,String]) (defaults to: undef)

    Refer to PostgreSQL configuration settings callbacks ‘on_start`

  • callback_on_stop (Variant[Undef,String]) (defaults to: undef)

    Refer to PostgreSQL configuration settings callbacks ‘on_stop`

  • pgsql_connect_address (Variant[Undef,String]) (defaults to: "${facts['networking']['fqdn']}:5432")

    Refer to PostgreSQL configuration settings ‘connect_address` setting

  • pgsql_create_replica_methods (Array[String]) (defaults to: ['basebackup'])

    Refer to PostgreSQL configuration settings ‘create_replica_methods` setting

  • pgsql_data_dir (Optional[Stdlib::Unixpath]) (defaults to: undef)

    Refer to PostgreSQL configuration settings ‘data_dir` setting

  • pgsql_config_dir (Variant[Undef,String]) (defaults to: undef)

    Refer to PostgreSQL configuration settings ‘config_dir` setting

  • pgsql_bin_dir (Variant[Undef,String]) (defaults to: undef)

    Refer to PostgreSQL configuration settings ‘bin_dir` setting

  • pgsql_listen (String) (defaults to: '0.0.0.0:5432')

    Refer to PostgreSQL configuration settings ‘listen` setting

  • pgsql_use_unix_socket (Boolean) (defaults to: false)

    Refer to PostgreSQL configuration settings ‘use_unix_socket` setting

  • pgsql_pgpass_path (String) (defaults to: '/tmp/pgpass0')

    Refer to PostgreSQL configuration settings ‘pgpass_path` setting

  • pgsql_recovery_conf (Hash) (defaults to: {})

    Refer to PostgreSQL configuration settings ‘recovery_conf` setting

  • pgsql_custom_conf (Variant[Undef,String]) (defaults to: undef)

    Refer to PostgreSQL configuration settings ‘custom_conf` setting

  • pgsql_parameters (Hash) (defaults to: {})

    Refer to PostgreSQL configuration settings ‘parameters` setting

  • pgsql_pg_hba (Array[String]) (defaults to: [])

    Refer to PostgreSQL configuration settings ‘pg_hba` setting

  • pgsql_pg_ctl_timeout (Integer) (defaults to: 60)

    Refer to PostgreSQL configuration settings ‘pg_ctl_timeout` setting

  • pgsql_use_pg_rewind (Boolean) (defaults to: true)

    Refer to PostgreSQL configuration settings ‘use_pg_rewind` setting

  • pgsql_remove_data_directory_on_rewind_failure (Boolean) (defaults to: false)

    Refer to PostgreSQL configuration settings ‘remove_data_directory_on_rewind_failure` setting

  • pgsql_replica_method (Array[Hash]) (defaults to: [])

    Refer to PostgreSQL configuration settings ‘replica_method` setting

  • manage_postgresql_repo (Boolean) (defaults to: true)

    Should the postgresql module manage the package repo

  • use_consul (Boolean) (defaults to: false)

    Boolean to use Consul for configuration storage

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

    Refer to Consul configuration ‘host` setting

  • consul_url (Variant[Undef,String]) (defaults to: undef)

    Refer to Consul configuration ‘url` setting

  • consul_port (Stdlib::Port) (defaults to: 8500)

    Refer to Consul configuration ‘port` setting

  • consul_scheme (Enum['http','https']) (defaults to: 'http')

    Refer to Consul configuration ‘scheme` setting

  • consul_token (Variant[Undef,String]) (defaults to: undef)

    Refer to Consul configuration ‘token` setting

  • consul_verify (Boolean) (defaults to: false)

    Refer to Consul configuration ‘verify` setting

  • consul_register_service (Optional[Boolean]) (defaults to: undef)

    Refer to Consul configuration ‘register_service` setting

  • consul_service_check_interval (Optional[String]) (defaults to: undef)

    Refer to Consul configuration ‘service_check_interval` setting

  • consul_consistency (Optional[Enum['default', 'consistent', 'stale']]) (defaults to: undef)

    Refer to Consul configuration ‘consistency` setting

  • consul_cacert (Variant[Undef,String]) (defaults to: undef)

    Refer to Consul configuration ‘cacert` setting

  • consul_cert (Variant[Undef,String]) (defaults to: undef)

    Refer to Consul configuration ‘cert` setting

  • consul_key (Variant[Undef,String]) (defaults to: undef)

    Refer to Consul configuration ‘key` setting

  • consul_dc (Variant[Undef,String]) (defaults to: undef)

    Refer to Consul configuration ‘dc` setting

  • consul_checks (Variant[Undef,String]) (defaults to: undef)

    Refer to Consul configuration ‘checks` setting

  • use_etcd (Boolean) (defaults to: false)

    Boolean to use Etcd for configuration storage

  • etcd_version (Enum['etcd', 'etcd3']) (defaults to: 'etcd')

    Protocol version to use for etcd

  • etcd_host (String) (defaults to: '127.0.0.1:2379')

    Refer to Etcd configuration ‘host` setting

  • etcd_hosts (Array[String]) (defaults to: [])

    Refer to Etcd configuration ‘hosts` setting

  • etcd_url (Variant[Undef,String]) (defaults to: undef)

    Refer to Etcd configuration ‘url` setting

  • etcd_proxyurl (Variant[Undef,String]) (defaults to: undef)

    Refer to Etcd configuration ‘proxy` setting

  • etcd_srv (Variant[Undef,String]) (defaults to: undef)

    Refer to Etcd configuration ‘srv` setting

  • etcd_protocol (Enum['http','https']) (defaults to: 'http')

    Refer to Etcd configuration ‘protocol` setting

  • etcd_username (Variant[Undef,String]) (defaults to: undef)

    Refer to Etcd configuration ‘username` setting

  • etcd_password (Variant[Undef,String]) (defaults to: undef)

    Refer to Etcd configuration ‘password` setting

  • etcd_cacert (Variant[Undef,String]) (defaults to: undef)

    Refer to Etcd configuration ‘cacert` setting

  • etcd_cert (Variant[Undef,String]) (defaults to: undef)

    Refer to Etcd configuration ‘cert` setting

  • etcd_key (Variant[Undef,String]) (defaults to: undef)

    Refer to Etcd configuration ‘key` setting

  • use_exhibitor (Boolean) (defaults to: false)

    Boolean to use Exhibitor configuration storage

  • exhibitor_hosts (Array[String]) (defaults to: [])

    Refer to Exhibitor configuration ‘hosts` setting

  • exhibitor_poll_interval (Integer) (defaults to: 10)

    Refer to Exhibitor configuration ‘poll_interval` setting

  • exhibitor_port (Integer) (defaults to: 8080)

    Refer to Exhibitor configuration ‘port` setting

  • use_kubernetes (Boolean) (defaults to: false)

    Boolean to use Kubernetes configuration storage

  • kubernetes_namespace (String) (defaults to: 'default')

    Refer to Kubernetes configuration ‘namespace` setting

  • kubernetes_labels (Hash) (defaults to: {})

    Refer to Kubernetes configuration ‘labels` setting

  • kubernetes_scope_label (Variant[Undef,String]) (defaults to: undef)

    Refer to Kubernetes configuration ‘scope_label` setting

  • kubernetes_role_label (Variant[Undef,String]) (defaults to: undef)

    Refer to Kubernetes configuration ‘role_label` setting

  • kubernetes_use_endpoints (Boolean) (defaults to: false)

    Refer to Kubernetes configuration ‘use_endpoints` setting

  • kubernetes_pod_ip (Variant[Undef,String]) (defaults to: undef)

    Refer to Kubernetes configuration ‘pod_ip` setting

  • kubernetes_ports (Variant[Undef,String]) (defaults to: undef)

    Refer to Kubernetes configuration ‘ports` setting

  • restapi_ciphers (Optional[String]) (defaults to: undef)

    Refer to REST API configuration ‘ciphers` setting

  • restapi_connect_address (String) (defaults to: "${facts['networking']['fqdn']}:8008")

    Refer to REST API configuration ‘connect_address` setting

  • restapi_listen (String) (defaults to: '0.0.0.0:8008')

    Refer to REST API configuration ‘listen` setting

  • restapi_username (Variant[Undef,String]) (defaults to: undef)

    Refer to REST API configuration ‘username` setting

  • restapi_password (Variant[Undef,String]) (defaults to: undef)

    Refer to REST API configuration ‘password` setting

  • restapi_certfile (Variant[Undef,String]) (defaults to: undef)

    Refer to REST API configuration ‘certfile` setting

  • restapi_keyfile (Variant[Undef,String]) (defaults to: undef)

    Refer to REST API configuration ‘keyfile` setting

  • restapi_cafile (Optional[String]) (defaults to: undef)

    Refer to REST API configuration ‘cafile` setting

  • restapi_verify_client (Optional[Enum['none','optional','required']]) (defaults to: undef)

    Refer to REST API configuration ‘verify_client` setting

  • use_zookeeper (Boolean) (defaults to: false)

    Boolean to enable Zookeeper configuration storage

  • zookeeper_hosts (Array[String[1]]) (defaults to: [])

    Refer to Zookeeper configuration ‘hosts` setting

  • watchdog_mode (Enum['off','automatic','required']) (defaults to: 'automatic')

    Refer to Watchdog configuration ‘mode` setting

  • watchdog_device (Stdlib::Absolutepath) (defaults to: '/dev/watchdog')

    Refer to Watchdog configuration ‘device` setting

  • watchdog_safety_margin (Integer) (defaults to: 5)

    Refer to Watchdog configuration ‘safety_margin` setting

  • manage_postgresql (Boolean) (defaults to: true)

    Boolean to determine if postgresql is managed

  • postgresql_version (Optional[String[1]]) (defaults to: undef)

    Version of postgresql passed to postgresql::globals class

  • package_name (String[1]) (defaults to: 'patroni')

    Patroni package name, only used when ‘install_method` is `package`

  • version (String[1]) (defaults to: 'present')

    Version of Patroni to install

  • install_dependencies (Array[String[1]]) (defaults to: [])

    Install dependencies, only used when ‘install_method` is `pip`

  • manage_python (Boolean) (defaults to: true)

    Manage Python class, only used when ‘install_method` is `pip`

  • install_method (Enum['package','pip']) (defaults to: 'pip')

    Install method

  • install_dir (Stdlib::Absolutepath) (defaults to: '/opt/app/patroni')

    Install directory, only used when ‘install_method` is `pip`

  • python_class_version (String[1]) (defaults to: '36')

    The version of Python to pass to Python class Only used when ‘install_method` is `pip`

  • python_venv_version (String[1]) (defaults to: '3.6')

    The version of Python to pass to Python virtualenv defined type Only used when ‘install_method` is `pip`

  • manage_venv_package (Boolean) (defaults to: true)

    Whether to manage the Python venv package

  • config_path (Stdlib::Absolutepath) (defaults to: '/opt/app/patroni/etc/postgresql.yml')

    Path to Patroni configuration file

  • config_owner (String[1]) (defaults to: 'postgres')

    Patroni configuration file owner

  • config_group (String[1]) (defaults to: 'postgres')

    Patroni configuration file group

  • config_mode (Stdlib::Filemode) (defaults to: '0600')

    Patroni configuration file mode

  • service_name (String[1]) (defaults to: 'patroni')

    Name of Patroni service

  • service_ensure (Enum['running', 'stopped']) (defaults to: 'running')

    Patroni service ensure property

  • service_enable (Boolean) (defaults to: true)

    Patroni service enable property

  • custom_pip_provider (Optional[String[1]]) (defaults to: undef)

    Use custom pip path when installing pip packages

  • is_standby (Boolean) (defaults to: false)

    Boolean to use Standby cluster

  • standby_cluster_host (String) (defaults to: '127.0.0.1')

    Refer to Standby configuration ‘host` setting

  • standby_cluster_port (Stdlib::Port) (defaults to: 5432)

    Refer to Standby configuration ‘port` setting

  • standby_cluster_primary_slot_name (String[1]) (defaults to: 'patroni')

    Refer to Standby configuration ‘slot` setting

  • http_proxy (Optional[Stdlib::HTTPUrl]) (defaults to: undef)

    URI for an http(s) proxy, used for pip commands



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
# File 'manifests/init.pp', line 257

class patroni (

  # Global Settings
  String[1] $scope,
  String[1] $namespace = '/service/',
  String $hostname = $facts['networking']['hostname'],

  # Bootstrap Settings
  Integer $dcs_loop_wait = 10,
  Integer $dcs_ttl = 30,
  Integer $dcs_retry_timeout = 10,
  Integer $dcs_maximum_lag_on_failover = 1048576,
  Integer $dcs_master_start_timeout = 300,
  Boolean $dcs_synchronous_mode = false,
  Boolean $dcs_synchronous_mode_strict = false,
  Boolean $dcs_postgresql_use_pg_rewind = true,
  Boolean $dcs_postgresql_use_slots = true,
  Hash $dcs_postgresql_recovery_conf = {},
  Hash $dcs_postgresql_parameters = {},
  String[1] $bootstrap_method = 'initdb',
  Boolean $initdb_data_checksums = true,
  String $initdb_encoding = 'UTF8',
  String $initdb_locale = 'en_US.utf8',
  Array[String] $bootstrap_pg_hba = [
    'host all all 0.0.0.0/0 md5',
    'host replication rep_user 0.0.0.0/0 md5',
  ],
  Hash $bootstrap_users = {},
  Variant[Undef,String] $bootstrap_post_bootstrap = undef,
  Variant[Undef,String] $bootstrap_post_init = undef,
  Boolean $is_standby = false,
  String $standby_cluster_host = '127.0.0.1',
  Stdlib::Port $standby_cluster_port = 5432,
  String[1] $standby_cluster_primary_slot_name = 'patroni',

  # PostgreSQL Settings
  String $superuser_username = 'postgres',
  String $superuser_password = 'changeme',
  String $replication_username = 'rep_user',
  String $replication_password = 'changeme',
  Variant[Undef,String] $callback_on_reload = undef,
  Variant[Undef,String] $callback_on_restart = undef,
  Variant[Undef,String] $callback_on_role_change = undef,
  Variant[Undef,String] $callback_on_start = undef,
  Variant[Undef,String] $callback_on_stop = undef,
  Variant[Undef,String] $pgsql_connect_address = "${facts['networking']['fqdn']}:5432",
  Array[String] $pgsql_create_replica_methods = ['basebackup'],
  Optional[Stdlib::Unixpath] $pgsql_data_dir = undef,
  Variant[Undef,String] $pgsql_config_dir = undef,
  Variant[Undef,String] $pgsql_bin_dir = undef,
  String $pgsql_listen = '0.0.0.0:5432',
  Boolean $pgsql_use_unix_socket = false,
  String $pgsql_pgpass_path = '/tmp/pgpass0',
  Hash $pgsql_recovery_conf = {},
  Variant[Undef,String]  $pgsql_custom_conf = undef,
  Hash $pgsql_parameters = {},
  Array[String] $pgsql_pg_hba = [],
  Integer $pgsql_pg_ctl_timeout = 60,
  Boolean $pgsql_use_pg_rewind = true,
  Boolean $pgsql_remove_data_directory_on_rewind_failure = false,
  Array[Hash] $pgsql_replica_method = [],
  Boolean $manage_postgresql_repo = true,

  # Consul Settings
  Boolean $use_consul = false,
  String $consul_host = 'localhost',
  Variant[Undef,String] $consul_url = undef,
  Stdlib::Port $consul_port = 8500,
  Enum['http','https'] $consul_scheme = 'http',
  Variant[Undef,String] $consul_token = undef,
  Boolean $consul_verify = false,
  Optional[Boolean] $consul_register_service = undef,
  Optional[String] $consul_service_check_interval = undef,
  Optional[Enum['default', 'consistent', 'stale']] $consul_consistency = undef,
  Variant[Undef,String] $consul_cacert = undef,
  Variant[Undef,String] $consul_cert = undef,
  Variant[Undef,String] $consul_key = undef,
  Variant[Undef,String] $consul_dc = undef,
  Variant[Undef,String] $consul_checks = undef,

  # Etcd Settings
  Boolean $use_etcd = false,
  Enum['etcd', 'etcd3'] $etcd_version = 'etcd',
  String $etcd_host = '127.0.0.1:2379',
  Array[String] $etcd_hosts = [],
  Variant[Undef,String] $etcd_url = undef,
  Variant[Undef,String] $etcd_proxyurl = undef,
  Variant[Undef,String] $etcd_srv = undef,
  Enum['http','https'] $etcd_protocol = 'http',
  Variant[Undef,String] $etcd_username = undef,
  Variant[Undef,String] $etcd_password = undef,
  Variant[Undef,String] $etcd_cacert = undef,
  Variant[Undef,String] $etcd_cert = undef,
  Variant[Undef,String] $etcd_key = undef,

  # Exhibitor Settings
  Boolean $use_exhibitor = false,
  Array[String] $exhibitor_hosts = [],
  Integer $exhibitor_poll_interval = 10,
  Integer $exhibitor_port = 8080,

  # Kubernetes Settings
  Boolean $use_kubernetes = false,
  String $kubernetes_namespace = 'default',
  Hash $kubernetes_labels = {},
  Variant[Undef,String] $kubernetes_scope_label = undef,
  Variant[Undef,String] $kubernetes_role_label = undef,
  Boolean $kubernetes_use_endpoints = false,
  Variant[Undef,String] $kubernetes_pod_ip = undef,
  Variant[Undef,String] $kubernetes_ports = undef,

  # REST API Settings
  Optional[String] $restapi_ciphers = undef,
  String $restapi_connect_address = "${facts['networking']['fqdn']}:8008",
  String $restapi_listen = '0.0.0.0:8008',
  Variant[Undef,String] $restapi_username = undef,
  Variant[Undef,String] $restapi_password = undef,
  Variant[Undef,String] $restapi_certfile = undef,
  Variant[Undef,String] $restapi_keyfile = undef,
  Optional[String] $restapi_cafile = undef,
  Optional[Enum['none','optional','required']] $restapi_verify_client = undef,

  # ZooKeeper Settings
  Boolean $use_zookeeper = false,
  Array[String[1]] $zookeeper_hosts = [],

  # Watchdog Settings
  Enum['off','automatic','required'] $watchdog_mode = 'automatic',
  Stdlib::Absolutepath $watchdog_device = '/dev/watchdog',
  Integer $watchdog_safety_margin = 5,

  # Module Specific Settings
  Boolean $manage_postgresql = true,
  Optional[String[1]] $postgresql_version = undef,
  String[1] $package_name = 'patroni',
  String[1] $version = 'present',
  Array[String[1]] $install_dependencies = [],
  Boolean $manage_python = true,
  Enum['package','pip'] $install_method = 'pip',
  Stdlib::Absolutepath $install_dir = '/opt/app/patroni',
  String[1] $python_class_version = '36',
  String[1] $python_venv_version = '3.6',
  Boolean $manage_venv_package = true,
  Stdlib::Absolutepath $config_path = '/opt/app/patroni/etc/postgresql.yml',
  String[1] $config_owner = 'postgres',
  String[1] $config_group = 'postgres',
  Stdlib::Filemode $config_mode = '0600',
  String[1] $service_name = 'patroni',
  Enum['running', 'stopped'] $service_ensure = 'running',
  Boolean $service_enable = true,
  Optional[String[1]] $custom_pip_provider = undef,
  Optional[Stdlib::HTTPUrl] $http_proxy = undef,
) {
  if $manage_postgresql {
    class { 'postgresql::globals':
      encoding            => 'UTF-8',
      locale              => 'en_US.UTF-8',
      manage_package_repo => $manage_postgresql_repo,
      version             => $postgresql_version,
    }

    include postgresql::params

    $default_data_dir = $postgresql::params::datadir
    $default_bin_dir = $postgresql::params::bindir

    if $manage_postgresql_repo == true {
      $postgres_repo_require = 'Class[Postgresql::Repo]'
    } else {
      $postgres_repo_require = undef
    }

    package { 'patroni-postgresql-package':
      ensure  => present,
      name    => $postgresql::params::server_package_name,
      require => $postgres_repo_require,
      before  => Service['patroni'],
    }

    package { 'patroni-postgresql-devel-package':
      ensure  => present,
      name    => $postgresql::params::devel_package_name,
      require => $postgres_repo_require,
      before  => Service['patroni'],
    }
    if $install_method == 'pip' {
      Package['patroni-postgresql-devel-package'] -> Python::Pip['psycopg2']
    }

    if $facts['os']['family'] == 'RedHat' and $manage_postgresql_repo and $default_bin_dir != '/usr/bin' {
      file { '/usr/bin/pg_config':
        ensure => 'link',
        target => "${default_bin_dir}/pg_config",
      }
    }

    exec { 'patroni-clear-datadir':
      path        => '/usr/bin:/bin',
      command     => "/bin/rm -rf ${default_data_dir}",
      refreshonly => true,
      subscribe   => Package['patroni-postgresql-package'],
      before      => Service['patroni'],
    }
  } else {
    $default_data_dir = '/var/lib/patroni'
    $default_bin_dir = false
  }

  $_pgsql_data_dir = pick($pgsql_data_dir, $default_data_dir)
  $_pgsql_bin_dir = pick($pgsql_bin_dir, $default_bin_dir)

  if $install_method == 'pip' {
    $env_params = if $http_proxy {
      ["http_proxy=${http_proxy}", "https_proxy=${http_proxy}"]
    } else {
      []
    }
    if $manage_python {
      class { 'python':
        version             => $python_class_version,
        dev                 => 'present',
        venv                => 'present',
        manage_venv_package => $manage_venv_package,
      }
    }

    stdlib::ensure_packages($install_dependencies, { 'before' => Python::Pip['patroni'] })

    exec { 'patroni-mkdir-install_dir':
      command => "/bin/mkdir -p ${install_dir}",
      creates => $install_dir,
    }

    python::pyvenv { 'patroni':
      version     => $python_venv_version,
      venv_dir    => $install_dir,
      systempkgs  => true,
      environment => ["PIP_PREFIX=${install_dir}"] + $env_params,
      require     => Exec['patroni-mkdir-install_dir'],
    }

    if $custom_pip_provider {
      $virtualenv = undef
    } else {
      $virtualenv = $install_dir
    }

    python::pip { 'patroni':
      ensure       => $version,
      environment  => ["PIP_PREFIX=${install_dir}"] + $env_params,
      pip_provider => $custom_pip_provider,
      virtualenv   => $virtualenv,
      before       => File['patroni_config'],
    }

    $dependency_params = {
      'before'       => Python::Pip['patroni'],
      'pip_provider' => $custom_pip_provider,
      'virtualenv'   => $virtualenv,
      'environment'  => ["PIP_PREFIX=${install_dir}"] + $env_params,
    }

    python::pip { 'psycopg2': * => $dependency_params }

    if $use_consul {
      python::pip { 'python-consul': * => $dependency_params }
    }

    if $use_etcd {
      python::pip { 'python-etcd': * => $dependency_params }
    }

    if $use_exhibitor or $use_zookeeper {
      python::pip { 'kazoo': * => $dependency_params }
    }
  } else {
    package { 'patroni':
      ensure => $version,
      name   => $package_name,
      before => File['patroni_config'],
    }
  }

  if $install_method == 'pip' {
    $config_dir = dirname($config_path)
    file { 'patroni_config_dir':
      ensure  => 'directory',
      path    => $config_dir,
      owner   => 'postgres',
      group   => 'postgres',
      mode    => '0755',
      require => Python::Pyvenv['patroni'],
    }
  }

  file { 'patroni_config':
    ensure  => 'file',
    path    => $config_path,
    owner   => $config_owner,
    group   => $config_group,
    mode    => $config_mode,
    content => template('patroni/postgresql.yml.erb'),
    notify  => Service['patroni'],
  }

  if $install_method == 'pip' {
    systemd::unit_file { "${service_name}.service":
      content => template('patroni/patroni.service.erb'),
      notify  => Service['patroni'],
    }
  }

  service { 'patroni':
    ensure => $service_ensure,
    name   => $service_name,
    enable => $service_enable,
  }

  $patronictl = "${install_dir}/bin/patronictl"
  patronictl_config { 'puppet':
    path   => $patronictl,
    config => $config_path,
  }
}