From 845433db46ef52d61315b0f16e73be6d7cbc4347 Mon Sep 17 00:00:00 2001 From: Taylan Develioglu Date: Thu, 15 Sep 2016 11:42:02 +0200 Subject: [PATCH 1/5] Don't fear the alphabet --- manifests/check.pp | 46 ++++++++++---------- manifests/init.pp | 101 ++++++++++++++++++++++--------------------- manifests/params.pp | 14 +++--- manifests/service.pp | 38 ++++++++-------- manifests/watch.pp | 38 ++++++++-------- 5 files changed, 119 insertions(+), 118 deletions(-) diff --git a/manifests/check.pp b/manifests/check.pp index 53c940d1..1a4ef64b 100644 --- a/manifests/check.pp +++ b/manifests/check.pp @@ -9,56 +9,56 @@ # Define availability of check. Use 'absent' to remove existing checks. # Defaults to 'present' # +# [*http*] +# HTTP endpoint for the service healthcheck +# # [*id*] # The id for the check (defaults to $title) # -# [*ttl*] -# Value in seconds before the http endpoint considers a failing healthcheck -# to be "HARD" down. +# [*interval*] +# Value in seconds for the interval between runs of the check # -# [*http*] -# HTTP endpoint for the service healthcheck +# [*notes*] +# Human readable description of the check # # [*script*] # Full path to the location of the healthcheck script. Must be nagios # compliant with regards to the return codes. # +# [*service_id*] +# An optional service_id to match this check against +# +# [*status*] +# The default state of the check when it is registered against a consul +# agent. Should be either "critical" or "passing" +# # [*tcp*] # The IP/hostname and port for the service healthcheck. Should be in # 'hostname:port' format. # -# [*interval*] -# Value in seconds for the interval between runs of the check -# -# [*service_id*] -# An optional service_id to match this check against -# # [*timeout*] # A timeout value for HTTP request only # -# [*notes*] -# Human readable description of the check -# # [*token*] # ACL token for interacting with the catalog (must be 'management' type) # -# [*status*] -# The default state of the check when it is registered against a consul -# agent. Should be either "critical" or "passing" +# [*ttl*] +# Value in seconds before the http endpoint considers a failing healthcheck +# to be "HARD" down. # define consul::check( $ensure = present, - $id = $title, - $ttl = undef, $http = undef, - $script = undef, - $tcp = undef, + $id = $title, $interval = undef, + $notes = undef, + $script = undef, $service_id = undef, + $status = undef, + $tcp = undef, $timeout = undef, - $notes = undef, $token = undef, - $status = undef, + $ttl = undef, ) { include consul diff --git a/manifests/init.pp b/manifests/init.pp index ecfac51b..d3062980 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -4,8 +4,8 @@ # # === Parameters # -# [*version*] -# Specify version of consul binary to download. +# [*archive_path*] +# Path used when installing consul via the url. Defaults to /opt/puppet-archive # # [*config_hash*] # Use this to populate the JSON config file for consul. @@ -13,85 +13,86 @@ # [*config_mode*] # Use this to set the JSON config file mode for consul. # -# [*pretty_config*] -# Generates a human readable JSON config file. Defaults to `false`. +# [*extra_options*] +# Extra arguments to be passed to the consul agent # -# [*pretty_config_indent*] -# Toggle indentation for human readable JSON file. Defaults to `4`. +# [*init_style*] +# What style of init system your system uses. # # [*install_method*] # Valid strings: `package` - install via system package # `url` - download and extract from a url. Defaults to `url`. # `none` - disable install. # -# [*package_name*] -# Only valid when the install_method == package. Defaults to `consul`. +# [*pretty_config*] +# Generates a human readable JSON config file. Defaults to `false`. +# +# [*pretty_config_indent*] +# Toggle indentation for human readable JSON file. Defaults to `4`. # # [*package_ensure*] # Only valid when the install_method == package. Defaults to `latest`. # -# [*ui_package_name*] -# Only valid when the install_method == package. Defaults to `consul_ui`. -# -# [*ui_package_ensure*] -# Only valid when the install_method == package. Defaults to `latest`. +# [*package_name*] +# Only valid when the install_method == package. Defaults to `consul`. # +# [*purge_config_dir*] +# Purge config files no longer generated by Puppet +# # [*restart_on_change*] # Determines whether to restart consul agent on $config_hash changes. # This will not affect reloads when service, check or watch configs change. # Defaults to `true`. # -# [*extra_options*] -# Extra arguments to be passed to the consul agent +# [*ui_package_ensure*] +# Only valid when the install_method == package. Defaults to `latest`. # -# [*init_style*] -# What style of init system your system uses. +# [*ui_package_name*] +# Only valid when the install_method == package. Defaults to `consul_ui`. +# +# [*version*] +# Specify version of consul binary to download. # -# [*purge_config_dir*] -# Purge config files no longer generated by Puppet -# -# [*archive_path*] -# Path used when installing consul via the url. Defaults to /opt/puppet-archive class consul ( - $manage_user = true, - $user = 'consul', - $manage_group = true, + $acls = {}, + $arch = $consul::params::arch, + $archive_path = '/opt/puppet-archive', + $bin_dir = '/usr/local/bin', + $checks = {}, + $config_defaults = {}, + $config_dir = '/etc/consul', + $config_hash = {}, + $config_mode = $consul::params::config_mode, + $download_extension = $consul::params::download_extension, + $download_url = undef, + $download_url_base = $consul::params::download_url_base, $extra_groups = [], - $purge_config_dir = true, + $extra_options = '', $group = 'consul', - $join_wan = false, - $bin_dir = '/usr/local/bin', - $archive_path = '/opt/puppet-archive', - $arch = $consul::params::arch, - $version = $consul::params::version, + $init_style = $consul::params::init_style, $install_method = $consul::params::install_method, + $join_wan = false, + $manage_group = true, + $manage_service = true, + $manage_user = true, $os = $consul::params::os, - $download_url = undef, - $download_url_base = $consul::params::download_url_base, - $download_extension = $consul::params::download_extension, - $package_name = $consul::params::package_name, $package_ensure = $consul::params::package_ensure, - $ui_download_url = undef, - $ui_download_url_base = $consul::params::ui_download_url_base, - $ui_download_extension = $consul::params::ui_download_extension, - $ui_package_name = $consul::params::ui_package_name, - $ui_package_ensure = $consul::params::ui_package_ensure, - $config_dir = '/etc/consul', - $extra_options = '', - $config_hash = {}, - $config_defaults = {}, - $config_mode = $consul::params::config_mode, + $package_name = $consul::params::package_name, $pretty_config = false, $pretty_config_indent = 4, + $purge_config_dir = true, + $restart_on_change = true, $service_enable = true, $service_ensure = 'running', - $manage_service = true, - $restart_on_change = true, - $init_style = $consul::params::init_style, $services = {}, + $ui_download_extension = $consul::params::ui_download_extension, + $ui_download_url = undef, + $ui_download_url_base = $consul::params::ui_download_url_base, + $ui_package_ensure = $consul::params::ui_package_ensure, + $ui_package_name = $consul::params::ui_package_name, + $user = 'consul', + $version = $consul::params::version, $watches = {}, - $checks = {}, - $acls = {}, ) inherits consul::params { # lint:ignore:140chars diff --git a/manifests/params.pp b/manifests/params.pp index a774dff0..39020660 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -5,17 +5,17 @@ # class consul::params { + $config_mode = '0660' + $download_extension = 'zip' + $download_url_base = 'https://releases.hashicorp.com/consul/' $install_method = 'url' - $package_name = 'consul' $package_ensure = 'latest' - $download_url_base = 'https://releases.hashicorp.com/consul/' - $download_extension = 'zip' - $ui_package_name = 'consul_ui' - $ui_package_ensure = 'latest' - $ui_download_url_base = 'https://releases.hashicorp.com/consul/' + $package_name = 'consul' $ui_download_extension = 'zip' + $ui_download_url_base = 'https://releases.hashicorp.com/consul/' + $ui_package_ensure = 'latest' + $ui_package_name = 'consul_ui' $version = '0.5.2' - $config_mode = '0660' case $::architecture { 'x86_64', 'amd64': { $arch = 'amd64' } diff --git a/manifests/service.pp b/manifests/service.pp index 4d06222f..3120e198 100644 --- a/manifests/service.pp +++ b/manifests/service.pp @@ -5,44 +5,44 @@ # # == Parameters # +# [*address*] +# IP address the service is running at. +# +# [*checks*] +# If provided an array of checks that will be added to this service +# +# [*enable_tag_override*] +# enableTagOverride support for service. Defaults to False. +# # [*ensure*] # Define availability of service. Use 'absent' to remove existing services. # Defaults to 'present' # -# [*service_name*] -# Name of the service. Defaults to title. -# # [*id*] # The unique ID of the service on the node. Defaults to title. # -# [*tags*] -# Array of strings. -# -# [*address*] -# IP address the service is running at. -# # [*port*] # TCP port the service runs on. # -# [*checks*] -# If provided an array of checks that will be added to this service +# [*service_name*] +# Name of the service. Defaults to title. +# +# [*tags*] +# Array of strings. # # [*token*] # ACL token for interacting with the catalog (must be 'management' type) # -# [*enable_tag_override*] -# enableTagOverride support for service. Defaults to False. -# define consul::service( + $address = undef, + $checks = [], + $enable_tag_override = false, $ensure = present, - $service_name = $title, $id = $title, - $tags = [], - $address = undef, $port = undef, - $checks = [], + $service_name = $title, + $tags = [], $token = undef, - $enable_tag_override = false, ) { include ::consul diff --git a/manifests/watch.pp b/manifests/watch.pp index ee2caa15..d617fca1 100644 --- a/manifests/watch.pp +++ b/manifests/watch.pp @@ -5,28 +5,28 @@ # # == Parameters # +# [*datacenter*] +# String overriding consul's default datacenter. +# # [*ensure*] # Define availability of watch. Use 'absent' to remove existing watches. # Defaults to 'present' # +# [*event_name*] +# Name of an event to watch for. +# # [*handler*] # Full path to the script that will be excuted. # -# [*datacenter*] -# String overriding consul's default datacenter. -# -# [*token*] -# String to override the default token. -# -# [*type*] -# Type of data to watch. (Like key, service, services, nodes) -# # [*key*] # Watch a specific key. # # [*keyprefix*] # Watch a whole keyprefix # +# [*passingonly*] +# Watch only those services that are passing healthchecks. +# # [*service*] # Watch a particular service # @@ -34,28 +34,28 @@ # This actually maps to the "tag" param for service watches. # (`tag` is a puppet builtin metaparameter) # -# [*passingonly*] -# Watch only those services that are passing healthchecks. -# # [*state*] # Watch a state change on a service healthcheck. # -# [*event_name*] -# Name of an event to watch for. +# [*token*] +# String to override the default token. +# +# [*type*] +# Type of data to watch. (Like key, service, services, nodes) # define consul::watch( + $datacenter = undef, $ensure = present, + $event_name = undef, $handler = undef, - $datacenter = undef, - $token = undef, - $type = undef, $key = undef, $keyprefix = undef, + $passingonly = undef, $service = undef, $service_tag = undef, - $passingonly = undef, $state = undef, - $event_name = undef, + $token = undef, + $type = undef, ) { include consul $id = $title From 3b11b523b1daecfac4d76aa55131878fe35ca2a5 Mon Sep 17 00:00:00 2001 From: Taylan Develioglu Date: Thu, 15 Sep 2016 13:16:36 +0200 Subject: [PATCH 2/5] Complete parameter docstrings --- manifests/init.pp | 142 ++++++++++++++++++++++++++++++++++++---------- 1 file changed, 113 insertions(+), 29 deletions(-) diff --git a/manifests/init.pp b/manifests/init.pp index d3062980..c7d5359a 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -1,58 +1,142 @@ # == Class: consul -# -# Installs, configures, and manages consul -# +# +# Installs, configures and manages consul +# # === Parameters -# +# +# [*acls*] +# Hash of consul_acl resources to create. +# +# [*arch*] +# Architecture of consul binary to download. +# # [*archive_path*] -# Path used when installing consul via the url. Defaults to /opt/puppet-archive -# +# Path used when installing consul via the url. +# +# [*bin_dir*] +# Directory to create the symlink to the consul binary in. +# +# [*checks*] +# Hash of consul::check resources to create. +# +# [*config_defaults*] +# Configuration defaults hash. Gets merged with config_hash. +# +# [*config_dir*] +# Directory to place consul configuration files in. +# # [*config_hash*] # Use this to populate the JSON config file for consul. -# +# # [*config_mode*] # Use this to set the JSON config file mode for consul. -# +# +# [*download_extension*] +# The extension of the archive file containing the consul binary to download. +# +# [*download_url*] +# Fully qualified url to the location of the archive file containing the consul binary. +# +# [*download_url_base*] +# Base url to the location of the archive file containing the consul binary. +# +# [*extra_groups*] +# Extra groups to add the consul system user to. +# # [*extra_options*] # Extra arguments to be passed to the consul agent -# +# +# [*group*] +# Name of the group that should own the consul configuration files. +# # [*init_style*] # What style of init system your system uses. -# +# # [*install_method*] # Valid strings: `package` - install via system package # `url` - download and extract from a url. Defaults to `url`. # `none` - disable install. -# -# [*pretty_config*] -# Generates a human readable JSON config file. Defaults to `false`. -# -# [*pretty_config_indent*] -# Toggle indentation for human readable JSON file. Defaults to `4`. -# +# +# [*join_wan*] +# Whether to join the wan on service start. +# +# [*manage_group*] +# Whether to create/manage the group that should own the consul configuration files. +# +# [*manage_service*] +# Whether to manage the consul service. +# +# [*manage_user*] +# Whether to create/manage the user that should own consul's configuration files. +# +# [*os*] +# OS component in the name of the archive file containing the consul binary. +# # [*package_ensure*] -# Only valid when the install_method == package. Defaults to `latest`. -# +# Only valid when the install_method == package. Defaults to *]latest*]. +# # [*package_name*] -# Only valid when the install_method == package. Defaults to `consul`. -# +# Only valid when the install_method == package. Defaults to *]consul*]. +# +# [*pretty_config*] +# Generates a human readable JSON config file. Defaults to *]false*]. +# +# [*pretty_config_indent*] +# Toggle indentation for human readable JSON file. Defaults to *]4*]. +# # [*purge_config_dir*] # Purge config files no longer generated by Puppet -# +# # [*restart_on_change*] # Determines whether to restart consul agent on $config_hash changes. # This will not affect reloads when service, check or watch configs change. -# Defaults to `true`. -# +# Defaults to *]true*]. +# +# [*service_enable*] +# Whether to enable the consul service to start at boot. +# +# [*service_ensure*] +# Whether the consul service should be running or not. +# +# [*services*] +# Hash of consul::service resources to create. +# +# [*ui_download_extension*] +# The extension of the archive file containing the consul ui to download. +# +# [*ui_download_url*] +# Fully qualified url to the location of the archive file containing the consul ui. +# +# [*ui_download_url_base*] +# Base url to the location of the archive file containing the consul ui. +# # [*ui_package_ensure*] -# Only valid when the install_method == package. Defaults to `latest`. -# +# Only valid when the install_method == package. Defaults to *]latest*]. +# # [*ui_package_name*] -# Only valid when the install_method == package. Defaults to `consul_ui`. -# +# Only valid when the install_method == package. Defaults to *]consul_ui*]. +# +# [*user*] +# Name of the user that should own the consul configuration files. +# # [*version*] # Specify version of consul binary to download. -# +# +# [*watches*] +# Hash of consul::watch resources to create. +# +# === Examples +# +# @example +# class { '::consul': +# config_hash => { +# 'datacenter' => 'east-aws', +# 'node_name' => $::fqdn, +# 'pretty_config => true, +# 'retry-join' => ['172.16.0.1'], +# }, +# } +# class consul ( $acls = {}, $arch = $consul::params::arch, From e38ff31dac9d1709dcb28259b1b2f4285b40933f Mon Sep 17 00:00:00 2001 From: Taylan Develioglu Date: Thu, 15 Sep 2016 13:39:20 +0200 Subject: [PATCH 3/5] Move all defaults to params --- manifests/init.pp | 78 ++++++++++++++++++++++----------------------- manifests/params.pp | 26 ++++++++++++++- 2 files changed, 64 insertions(+), 40 deletions(-) diff --git a/manifests/init.pp b/manifests/init.pp index c7d5359a..c92c4f94 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -138,45 +138,45 @@ # } # class consul ( - $acls = {}, - $arch = $consul::params::arch, - $archive_path = '/opt/puppet-archive', - $bin_dir = '/usr/local/bin', - $checks = {}, - $config_defaults = {}, - $config_dir = '/etc/consul', - $config_hash = {}, - $config_mode = $consul::params::config_mode, - $download_extension = $consul::params::download_extension, - $download_url = undef, - $download_url_base = $consul::params::download_url_base, - $extra_groups = [], - $extra_options = '', - $group = 'consul', - $init_style = $consul::params::init_style, - $install_method = $consul::params::install_method, - $join_wan = false, - $manage_group = true, - $manage_service = true, - $manage_user = true, - $os = $consul::params::os, - $package_ensure = $consul::params::package_ensure, - $package_name = $consul::params::package_name, - $pretty_config = false, - $pretty_config_indent = 4, - $purge_config_dir = true, - $restart_on_change = true, - $service_enable = true, - $service_ensure = 'running', - $services = {}, - $ui_download_extension = $consul::params::ui_download_extension, - $ui_download_url = undef, - $ui_download_url_base = $consul::params::ui_download_url_base, - $ui_package_ensure = $consul::params::ui_package_ensure, - $ui_package_name = $consul::params::ui_package_name, - $user = 'consul', - $version = $consul::params::version, - $watches = {}, + $acls = $::consul::params::acls, + $arch = $::consul::params::arch, + $archive_path = $::consul::params::archive_path, + $bin_dir = $::consul::params::bin_dir, + $checks = $::consul::params::checks, + $config_defaults = $::consul::params::config_defaults, + $config_dir = $::consul::params::config_dir, + $config_hash = $::consul::params::config_hash, + $config_mode = $::consul::params::config_mode, + $download_extension = $::consul::params::download_extension, + $download_url = $::consul::params::download_url, + $download_url_base = $::consul::params::download_url_base, + $extra_groups = $::consul::params::extra_groups, + $extra_options = $::consul::params::extra_options, + $group = $::consul::params::group, + $init_style = $::consul::params::init_style, + $install_method = $::consul::params::install_method, + $join_wan = $::consul::params::join_wan, + $manage_group = $::consul::params::manage_group, + $manage_service = $::consul::params::manage_service, + $manage_user = $::consul::params::manage_user, + $os = $::consul::params::os, + $package_ensure = $::consul::params::package_ensure, + $package_name = $::consul::params::package_name, + $pretty_config = $::consul::params::pretty_config, + $pretty_config_indent = $::consul::params::pretty_config_indent, + $purge_config_dir = $::consul::params::purge_config_dir, + $restart_on_change = $::consul::params::restart_on_change, + $service_enable = $::consul::params::service_enable, + $service_ensure = $::consul::params::service_ensure, + $services = $::consul::params::services, + $ui_download_extension = $::consul::params::ui_download_extension, + $ui_download_url = $::consul::params::ui_download_url, + $ui_download_url_base = $::consul::params::ui_download_url_base, + $ui_package_ensure = $::consul::params::ui_package_ensure, + $ui_package_name = $::consul::params::ui_package_name, + $user = $::consul::params::user, + $version = $::consul::params::version, + $watches = $::consul::params::watches, ) inherits consul::params { # lint:ignore:140chars diff --git a/manifests/params.pp b/manifests/params.pp index 39020660..b0cf905d 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -4,18 +4,42 @@ # It sets variables according to platform # class consul::params { - + $acls = {} + $archive_path = '/opt/puppet-archive' + $bin_dir = '/usr/local/bin' + $checks = {} + $config_defaults = {} + $config_dir = '/etc/consul' + $config_hash = {} $config_mode = '0660' $download_extension = 'zip' + $download_url = undef $download_url_base = 'https://releases.hashicorp.com/consul/' + $extra_groups = [] + $extra_options = '' + $group = 'consul' $install_method = 'url' + $join_wan = false + $manage_group = true + $manage_service = true + $manage_user = true $package_ensure = 'latest' $package_name = 'consul' + $pretty_config = false + $pretty_config_indent = 4 + $purge_config_dir = true + $restart_on_change = true + $service_enable = true + $service_ensure = 'running' + $services = {} $ui_download_extension = 'zip' + $ui_download_url = undef $ui_download_url_base = 'https://releases.hashicorp.com/consul/' $ui_package_ensure = 'latest' $ui_package_name = 'consul_ui' + $user = 'consul' $version = '0.5.2' + $watches = {} case $::architecture { 'x86_64', 'amd64': { $arch = 'amd64' } From f65ca12428c2c158ec4dc1c6c46b4a74dfb7c317 Mon Sep 17 00:00:00 2001 From: Taylan Develioglu Date: Thu, 15 Sep 2016 13:40:08 +0200 Subject: [PATCH 4/5] Remove unnecessary validation of hash merge result --- manifests/init.pp | 1 - 1 file changed, 1 deletion(-) diff --git a/manifests/init.pp b/manifests/init.pp index c92c4f94..7d8d99a2 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -199,7 +199,6 @@ validate_hash($acls) $config_hash_real = deep_merge($config_defaults, $config_hash) - validate_hash($config_hash_real) if $config_hash_real['data_dir'] { $data_dir = $config_hash_real['data_dir'] From e603a66e9ea024ea47042419b12bb3bdfdfe8ec6 Mon Sep 17 00:00:00 2001 From: Taylan Develioglu Date: Thu, 15 Sep 2016 13:47:23 +0200 Subject: [PATCH 5/5] Scope all variables --- manifests/check.pp | 10 +++---- manifests/config.pp | 18 ++++++------ manifests/init.pp | 14 ++++----- manifests/install.pp | 58 ++++++++++++++++++------------------- manifests/reload_service.pp | 8 ++--- manifests/run_service.pp | 16 +++++----- manifests/service.pp | 10 +++---- manifests/watch.pp | 10 +++---- 8 files changed, 72 insertions(+), 72 deletions(-) diff --git a/manifests/check.pp b/manifests/check.pp index 1a4ef64b..1e61f3bc 100644 --- a/manifests/check.pp +++ b/manifests/check.pp @@ -84,12 +84,12 @@ consul_validate_checks($check_hash[check]) $escaped_id = regsubst($id,'\/','_','G') - File[$consul::config_dir] -> + File[$::consul::config_dir] -> file { "${consul::config_dir}/check_${escaped_id}.json": ensure => $ensure, - owner => $consul::user, - group => $consul::group, - mode => $consul::config_mode, - content => consul_sorted_json($check_hash, $consul::pretty_config, $consul::pretty_config_indent), + owner => $::consul::user, + group => $::consul::group, + mode => $::consul::config_mode, + content => consul_sorted_json($check_hash, $::consul::pretty_config, $::consul::pretty_config_indent), } ~> Class['consul::reload_service'] } diff --git a/manifests/config.pp b/manifests/config.pp index 9bcf6048..fce61b6a 100644 --- a/manifests/config.pp +++ b/manifests/config.pp @@ -15,9 +15,9 @@ $purge = true, ) { - if $consul::init_style { + if $::consul::init_style { - case $consul::init_style { + case $::consul::init_style { 'upstart': { file { '/etc/init/consul.conf': mode => '0444', @@ -84,20 +84,20 @@ } } - file { $consul::config_dir: + file { $::consul::config_dir: ensure => 'directory', - owner => $consul::user, - group => $consul::group, + owner => $::consul::user, + group => $::consul::group, purge => $purge, recurse => $purge, } -> file { 'consul config.json': ensure => present, path => "${consul::config_dir}/config.json", - owner => $consul::user, - group => $consul::group, - mode => $consul::config_mode, - content => consul_sorted_json($config_hash, $consul::pretty_config, $consul::pretty_config_indent), + owner => $::consul::user, + group => $::consul::group, + mode => $::consul::config_mode, + content => consul_sorted_json($config_hash, $::consul::pretty_config, $::consul::pretty_config_indent), } } diff --git a/manifests/init.pp b/manifests/init.pp index 7d8d99a2..0aeefd58 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -73,16 +73,16 @@ # OS component in the name of the archive file containing the consul binary. # # [*package_ensure*] -# Only valid when the install_method == package. Defaults to *]latest*]. +# Only valid when the install_method == package. Defaults to `latest`. # # [*package_name*] -# Only valid when the install_method == package. Defaults to *]consul*]. +# Only valid when the install_method == package. Defaults to `consul`. # # [*pretty_config*] -# Generates a human readable JSON config file. Defaults to *]false*]. +# Generates a human readable JSON config file. Defaults to `false`. # # [*pretty_config_indent*] -# Toggle indentation for human readable JSON file. Defaults to *]4*]. +# Toggle indentation for human readable JSON file. Defaults to `4`. # # [*purge_config_dir*] # Purge config files no longer generated by Puppet @@ -90,7 +90,7 @@ # [*restart_on_change*] # Determines whether to restart consul agent on $config_hash changes. # This will not affect reloads when service, check or watch configs change. -# Defaults to *]true*]. +# Defaults to `true`. # # [*service_enable*] # Whether to enable the consul service to start at boot. @@ -111,10 +111,10 @@ # Base url to the location of the archive file containing the consul ui. # # [*ui_package_ensure*] -# Only valid when the install_method == package. Defaults to *]latest*]. +# Only valid when the install_method == package. Defaults to `latest`. # # [*ui_package_name*] -# Only valid when the install_method == package. Defaults to *]consul_ui*]. +# Only valid when the install_method == package. Defaults to `consul_ui`. # # [*user*] # Name of the user that should own the consul configuration files. diff --git a/manifests/install.pp b/manifests/install.pp index 8df3e108..e3b2321b 100644 --- a/manifests/install.pp +++ b/manifests/install.pp @@ -4,22 +4,22 @@ # class consul::install { - if $consul::data_dir { - file { $consul::data_dir: + if $::consul::data_dir { + file { $::consul::data_dir: ensure => 'directory', - owner => $consul::user, - group => $consul::group, + owner => $::consul::user, + group => $::consul::group, mode => '0755', } } - case $consul::install_method { + case $::consul::install_method { 'url': { - $install_path = $consul::archive_path + $install_path = $::consul::archive_path # only notify if we are installing a new version (work around for switching to archive module) - if $::consul_version != $consul::version { - $do_notify_service = $consul::notify_service + if $::consul_version != $::consul::version { + $do_notify_service = $::consul::notify_service } else { $do_notify_service = undef } @@ -35,7 +35,7 @@ }-> archive { "${install_path}/consul-${consul::version}.${consul::download_extension}": ensure => present, - source => $consul::real_download_url, + source => $::consul::real_download_url, extract => true, extract_path => "${install_path}/consul-${consul::version}", creates => "${install_path}/consul-${consul::version}/consul", @@ -51,7 +51,7 @@ target => "${install_path}/consul-${consul::version}/consul"; } - if ($consul::ui_dir and $consul::data_dir) { + if ($::consul::ui_dir and $::consul::data_dir) { # The 'dist' dir was removed from the web_ui archive in Consul version 0.6.0 if (versioncmp($::consul::version, '0.6.0') < 0) { @@ -67,35 +67,35 @@ }-> archive { "${install_path}/consul_web_ui-${consul::version}.zip": ensure => present, - source => $consul::real_ui_download_url, + source => $::consul::real_ui_download_url, extract => true, extract_path => "${install_path}/consul-${consul::version}_web_ui", creates => $archive_creates, }-> - file { $consul::ui_dir: + file { $::consul::ui_dir: ensure => 'symlink', target => $ui_symlink_target, } } } 'package': { - package { $consul::package_name: - ensure => $consul::package_ensure, + package { $::consul::package_name: + ensure => $::consul::package_ensure, } - if $consul::ui_dir { - package { $consul::ui_package_name: - ensure => $consul::ui_package_ensure, - require => Package[$consul::package_name] + if $::consul::ui_dir { + package { $::consul::ui_package_name: + ensure => $::consul::ui_package_ensure, + require => Package[$::consul::package_name] } } - if $consul::manage_user { - User[$consul::user] -> Package[$consul::package_name] + if $::consul::manage_user { + User[$::consul::user] -> Package[$::consul::package_name] } - if $consul::data_dir { - Package[$consul::package_name] -> File[$consul::data_dir] + if $::consul::data_dir { + Package[$::consul::package_name] -> File[$::consul::data_dir] } } 'none': {} @@ -104,19 +104,19 @@ } } - if $consul::manage_user { - user { $consul::user: + if $::consul::manage_user { + user { $::consul::user: ensure => 'present', system => true, - groups => $consul::extra_groups, + groups => $::consul::extra_groups, } - if $consul::manage_group { - Group[$consul::group] -> User[$consul::user] + if $::consul::manage_group { + Group[$::consul::group] -> User[$::consul::user] } } - if $consul::manage_group { - group { $consul::group: + if $::consul::manage_group { + group { $::consul::group: ensure => 'present', system => true, } diff --git a/manifests/reload_service.pp b/manifests/reload_service.pp index abb15037..f08cef5a 100644 --- a/manifests/reload_service.pp +++ b/manifests/reload_service.pp @@ -9,18 +9,18 @@ # Don't attempt to reload if we're not supposed to be running. # This can happen during pre-provisioning of a node. - if $consul::manage_service == true and $consul::service_ensure == 'running' { + if $::consul::manage_service == true and $::consul::service_ensure == 'running' { # Make sure we don't try to connect to 0.0.0.0, use 127.0.0.1 instead # This can happen if the consul agent RPC port is bound to 0.0.0.0 - if $consul::rpc_addr == '0.0.0.0' { + if $::consul::rpc_addr == '0.0.0.0' { $rpc_addr = '127.0.0.1' } else { - $rpc_addr = $consul::rpc_addr + $rpc_addr = $::consul::rpc_addr } exec { 'reload consul service': - path => [$consul::bin_dir,'/bin','/usr/bin'], + path => [$::consul::bin_dir,'/bin','/usr/bin'], command => "consul reload -rpc-addr=${rpc_addr}:${consul::rpc_port}", refreshonly => true, tries => 3, diff --git a/manifests/run_service.pp b/manifests/run_service.pp index 844dabf0..e1042763 100644 --- a/manifests/run_service.pp +++ b/manifests/run_service.pp @@ -5,24 +5,24 @@ # class consul::run_service { - $init_selector = $consul::init_style ? { + $init_selector = $::consul::init_style ? { 'launchd' => 'io.consul.daemon', default => 'consul', } - if $consul::manage_service == true and $consul::init_style { + if $::consul::manage_service == true and $::consul::init_style { service { 'consul': - ensure => $consul::service_ensure, + ensure => $::consul::service_ensure, name => $init_selector, - enable => $consul::service_enable, - provider => $consul::init_style, + enable => $::consul::service_enable, + provider => $::consul::init_style, } } - if $consul::join_wan { + if $::consul::join_wan { exec { 'join consul wan': - cwd => $consul::config_dir, - path => [$consul::bin_dir,'/bin','/usr/bin'], + cwd => $::consul::config_dir, + path => [$::consul::bin_dir,'/bin','/usr/bin'], command => "consul join -wan ${consul::join_wan}", unless => "consul members -wan -detailed | grep -vP \"dc=${consul::config_hash_real['datacenter']}\" | grep -P 'alive'", subscribe => Service['consul'], diff --git a/manifests/service.pp b/manifests/service.pp index 3120e198..a2a51324 100644 --- a/manifests/service.pp +++ b/manifests/service.pp @@ -66,10 +66,10 @@ $escaped_id = regsubst($id,'\/','_','G') file { "${consul::config_dir}/service_${escaped_id}.json": ensure => $ensure, - owner => $consul::user, - group => $consul::group, - mode => $consul::config_mode, - content => consul_sorted_json($service_hash, $consul::pretty_config, $consul::pretty_config_indent), - require => File[$consul::config_dir], + owner => $::consul::user, + group => $::consul::group, + mode => $::consul::config_mode, + content => consul_sorted_json($service_hash, $::consul::pretty_config, $::consul::pretty_config_indent), + require => File[$::consul::config_dir], } ~> Class['consul::reload_service'] } diff --git a/manifests/watch.pp b/manifests/watch.pp index d617fca1..01cdf326 100644 --- a/manifests/watch.pp +++ b/manifests/watch.pp @@ -133,12 +133,12 @@ watches => [delete_undef_values(merge($basic_hash, $type_hash))] } - File[$consul::config_dir] -> + File[$::consul::config_dir] -> file { "${consul::config_dir}/watch_${id}.json": ensure => $ensure, - owner => $consul::user, - group => $consul::group, - mode => $consul::config_mode, - content => consul_sorted_json($watch_hash, $consul::pretty_config, $consul::pretty_config_indent), + owner => $::consul::user, + group => $::consul::group, + mode => $::consul::config_mode, + content => consul_sorted_json($watch_hash, $::consul::pretty_config, $::consul::pretty_config_indent), } ~> Class['consul::reload_service'] }