Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(WIP) Puppet4 update #285

Merged
merged 4 commits into from
Nov 2, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions manifests/backend.pp
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
$section_name = $name,
$sort_options_alphabetic = undef,
$defaults = undef,
$config_file = undef,
Optional[Stdlib::Absolutepath] $config_file = undef,
) {

if defined(Haproxy::Listen[$section_name]) {
Expand All @@ -96,8 +96,6 @@
$_config_file = pick($config_file, inline_template($haproxy::params::config_file_tmpl))
}

validate_absolute_path(dirname($_config_file))

include ::haproxy::globals
$_sort_options_alphabetic = pick($sort_options_alphabetic, $haproxy::globals::sort_options_alphabetic)

Expand Down
4 changes: 1 addition & 3 deletions manifests/balancermember.pp
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@
$define_cookies = false,
$instance = 'haproxy',
$defaults = undef,
$config_file = undef,
Optional[Stdlib::Absolutepath] $config_file = undef,
$verifyhost = false,
$weight = undef,
) {
Expand All @@ -120,8 +120,6 @@
$_config_file = pick($config_file, inline_template($haproxy::params::config_file_tmpl))
}

validate_absolute_path(dirname($_config_file))

if $defaults == undef {
$order = "20-${listening_service}-01-${name}"
} else {
Expand Down
37 changes: 16 additions & 21 deletions manifests/frontend.pp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
#
# [*defaults_use_backend*]
# If defaults are used and a default backend is configured use the backend
# name for ordering. This means that the frontend is placed in the
# name for ordering. This means that the frontend is placed in the
# configuration file before the backend configuration.
# Defaults to true.
#
Expand Down Expand Up @@ -85,24 +85,24 @@
# Gary Larizza <gary@puppetlabs.com>
#
define haproxy::frontend (
$ports = undef,
$ipaddress = undef,
$bind = undef,
$mode = undef,
$collect_exported = true,
$options = {
'option' => [
$ports = undef,
$ipaddress = undef,
Optional[Hash] $bind = undef,
$mode = undef,
$collect_exported = true,
$options = {
'option' => [
'tcplog',
],
},
$instance = 'haproxy',
$section_name = $name,
$sort_options_alphabetic = undef,
$defaults = undef,
$defaults_use_backend = true,
$config_file = undef,
$instance = 'haproxy',
$section_name = $name,
$sort_options_alphabetic = undef,
$defaults = undef,
$defaults_use_backend = true,
Optional[Stdlib::Absolutepath] $config_file = undef,
# Deprecated
$bind_options = undef,
$bind_options = undef,
) {
if $ports and $bind {
fail('The use of $ports and $bind is mutually exclusive, please choose either one')
Expand All @@ -113,9 +113,6 @@
if $bind_options != '' {
warning('The $bind_options parameter is deprecated; please use $bind instead')
}
if $bind {
validate_hash($bind)
}

include ::haproxy::params

Expand All @@ -127,9 +124,7 @@
$_config_file = pick($config_file, inline_template($haproxy::params::config_file_tmpl))
}

validate_absolute_path(dirname($_config_file))

include ::haproxy::globals
include haproxy::globals
$_sort_options_alphabetic = pick($sort_options_alphabetic, $haproxy::globals::sort_options_alphabetic)

if $defaults == undef {
Expand Down
3 changes: 1 addition & 2 deletions manifests/globals.pp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
# Defaults to true.
#
class haproxy::globals (
$sort_options_alphabetic = true,
Boolean $sort_options_alphabetic = true,
) {
validate_bool($sort_options_alphabetic)
}
45 changes: 16 additions & 29 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -109,39 +109,26 @@
# }
#
class haproxy (
$package_ensure = 'present',
$package_name = $haproxy::params::package_name,
$service_ensure = 'running',
$service_manage = true,
$service_options = $haproxy::params::service_options,
$sysconfig_options = $haproxy::params::sysconfig_options,
$global_options = $haproxy::params::global_options,
$defaults_options = $haproxy::params::defaults_options,
$merge_options = $haproxy::params::merge_options,
$restart_command = undef,
$custom_fragment = undef,
$config_dir = $haproxy::params::config_dir,
$config_file = $haproxy::params::config_file,
$manage_config_dir = $haproxy::params::manage_config_dir,
$config_validate_cmd = $haproxy::params::config_validate_cmd,
Enum['present', 'absent', 'latest'] $package_ensure = 'present',
String $package_name = $haproxy::params::package_name,
Variant[Enum['running', 'stopped'], Boolean] $service_ensure = 'running',
Boolean $service_manage = true,
String $service_options = $haproxy::params::service_options,
$sysconfig_options = $haproxy::params::sysconfig_options,
Hash $global_options = $haproxy::params::global_options,
Hash $defaults_options = $haproxy::params::defaults_options,
Boolean $merge_options = $haproxy::params::merge_options,
$restart_command = undef,
$custom_fragment = undef,
Stdlib::Absolutepath $config_dir = $haproxy::params::config_dir,
Optional[Stdlib::Absolutepath] $config_file = $haproxy::params::config_file,
$manage_config_dir = $haproxy::params::manage_config_dir,

# Deprecated
$manage_service = undef,
$enable = undef,
$manage_service = undef,
$enable = undef,
) inherits haproxy::params {

if $service_ensure != true and $service_ensure != false {
if ! ($service_ensure in [ 'running','stopped']) {
fail('service_ensure parameter must be running, stopped, true, or false')
}
}
validate_string($package_name,$package_ensure)
validate_bool($service_manage)
validate_bool($merge_options)
validate_string($service_options)
validate_hash($global_options, $defaults_options)
validate_absolute_path($config_dir)

# NOTE: These deprecating parameters are implemented in this class,
# not in haproxy::instance. haproxy::instance is new and therefore
# there should be no legacy code that uses these deprecated
Expand Down
38 changes: 13 additions & 25 deletions manifests/instance.pp
Original file line number Diff line number Diff line change
Expand Up @@ -140,37 +140,27 @@
# call haproxy::instance_service.
#
define haproxy::instance (
$package_ensure = 'present',
$package_name = undef,
$service_ensure = 'running',
$service_manage = true,
$global_options = undef,
$defaults_options = undef,
$restart_command = undef,
$custom_fragment = undef,
$config_dir = undef,
$config_file = undef,
$merge_options = $haproxy::params::merge_options,
$service_options = $haproxy::params::service_options,
$sysconfig_options = $haproxy::params::sysconfig_options,
$config_validate_cmd = $haproxy::params::config_validate_cmd,
Optional[String] $package_name = undef,
Enum['absent', 'latest', 'present'] $package_ensure = 'present',
Variant[Enum['running', 'stopped'], Boolean] $service_ensure = 'running',
Boolean $service_manage = true,
Optional[Hash] $global_options = undef,
Optional[Hash] $defaults_options = undef,
$restart_command = undef,
$custom_fragment = undef,
$config_dir = undef,
Optional[Stdlib::Absolutepath] $config_file = undef,
$merge_options = $haproxy::params::merge_options,
$service_options = $haproxy::params::service_options,
$sysconfig_options = $haproxy::params::sysconfig_options,
) {

if $service_ensure != true and $service_ensure != false {
if ! ($service_ensure in [ 'running','stopped']) {
fail('service_ensure parameter must be running, stopped, true, or false')
}
}
validate_string($package_name,$package_ensure)
validate_bool($service_manage)

# Since this is a 'define', we can not use 'inherts haproxy::params'.
# Therefore, we "include haproxy::params" for any parameters we need.
include ::haproxy::params

$_global_options = pick($global_options, $haproxy::params::global_options)
$_defaults_options = pick($defaults_options, $haproxy::params::defaults_options)
validate_hash($_global_options,$_defaults_options)

# Determine instance_name based on:
# single-instance hosts: haproxy
Expand All @@ -191,8 +181,6 @@
$_config_file = pick($config_file, inline_template($haproxy::params::config_file_tmpl))
}

validate_absolute_path(dirname($_config_file))

if $instance_name == 'haproxy' {
$_config_dir = pick($config_dir, $haproxy::params::config_dir)
} else {
Expand Down
10 changes: 4 additions & 6 deletions manifests/instance_service.pp
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@
# The init.d script that will start/restart/reload this instance.
#
define haproxy::instance_service (
$haproxy_init_source = undef,
$haproxy_unit_template = undef,
$haproxy_package = 'haproxy',
$bindir = '/opt/haproxy/bin',
Optional[String] $haproxy_init_source = undef,
Optional[String]$haproxy_unit_template = undef,
String $haproxy_package = 'haproxy',
Stdlib::Absolutepath $bindir = '/opt/haproxy/bin',
) {

ensure_resource('package', $haproxy_package, {
Expand Down Expand Up @@ -80,7 +80,6 @@
if $::osfamily == 'RedHat' and $::operatingsystemmajrelease == '6' {

# init.d:
validate_string($haproxy_init_source)
file { $initfile:
ensure => file,
mode => '0744',
Expand All @@ -93,7 +92,6 @@
} else {

# systemd:
validate_string($haproxy_unit_template)
if $haproxy_package == 'haproxy' {
$wrapper = '/usr/sbin/haproxy-systemd-wrapper'
} else {
Expand Down
41 changes: 20 additions & 21 deletions manifests/listen.pp
Original file line number Diff line number Diff line change
Expand Up @@ -89,40 +89,41 @@
# Gary Larizza <gary@puppetlabs.com>
#
define haproxy::listen (
$ports = undef,
$ipaddress = undef,
$bind = undef,
$mode = undef,
$collect_exported = true,
$options = {
'option' => [
$ports = undef,
$ipaddress = undef,
Optional[Hash] $bind = undef,
$mode = undef,
$collect_exported = true,
$options = {
'option' => [
'tcplog',
],
<<<<<<< HEAD
'balance' => 'roundrobin',
=======
'balance' => 'roundrobin'
>>>>>>> replace validate_* with datatypes
},
$instance = 'haproxy',
$section_name = $name,
$sort_options_alphabetic = undef,
$defaults = undef,
$config_file = undef,
$instance = 'haproxy',
$section_name = $name,
$sort_options_alphabetic = undef,
$defaults = undef,
Optional[Stdlib::Absolutepath] $config_file = undef,
# Deprecated
$bind_options = '',
$bind_options = '',
) {
if $ports and $bind {
fail('The use of $ports and $bind is mutually exclusive, please choose either one')
}
if $ipaddress and $bind {
fail('The use of $ipaddress and $bind is mutually exclusive, please choose either one')
}
if $ipaddress == undef and $bind == undef {
if $ipaddress == undef and $bind == undef {
fail('Either $ipaddress or $bind is needed, please choose one')
}
if $bind_options != '' {
if $bind_options != '' {
warning('The $bind_options parameter is deprecated; please use $bind instead')
}
if $bind {
validate_hash($bind)
}

if defined(Haproxy::Backend[$section_name]) {
fail("An haproxy::backend resource was discovered with the same name (${section_name}) which is not supported")
Expand All @@ -138,9 +139,7 @@
$_config_file = pick($config_file, inline_template($haproxy::params::config_file_tmpl))
}

validate_absolute_path(dirname($_config_file))

include ::haproxy::globals
include haproxy::globals
$_sort_options_alphabetic = pick($sort_options_alphabetic, $haproxy::globals::sort_options_alphabetic)

if $defaults == undef {
Expand Down
10 changes: 3 additions & 7 deletions manifests/mapfile.pp
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,15 @@
# multiple HAproxy instances. Default: `[ 'haproxy' ]`
#
define haproxy::mapfile (
$mappings = [],
$ensure = 'present',
Array $mappings = [],
Enum['present', 'absent'] $ensure = 'present',
$owner = 'root',
$group = 'root',
$mode = '0644',
$instances = [ 'haproxy' ],
Array $instances = [ 'haproxy' ],
) {
$mapfile_name = $title

validate_re($ensure, '^present|absent$', "Haproxy::Mapfile[${mapfile_name}]: '${ensure}' is not supported for ensure. Allowed values are 'present' and 'absent'.") # lint:ignore:140chars
validate_array($mappings)
validate_array($instances)

$_instances = flatten($instances)

file { "haproxy_mapfile_${mapfile_name}":
Expand Down
15 changes: 4 additions & 11 deletions manifests/peer.pp
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,12 @@
define haproxy::peer (
$peers_name,
$port,
$server_names = $::hostname,
$ipaddresses = $::ipaddress,
$instance = 'haproxy',
$config_file = undef,
$server_names = $::hostname,
$ipaddresses = $::ipaddress,
$instance = 'haproxy',
Optional[Stdlib::Absolutepath] $config_file = undef,

#Deprecated
$ensure = undef,
) {
if $ensure {
warning('ensure is deprecated')
}
include ::haproxy::params

if $instance == 'haproxy' {
Expand All @@ -58,8 +53,6 @@
$_config_file = pick($config_file, inline_template($haproxy::params::config_file_tmpl))
}

validate_absolute_path(dirname($_config_file))

# Templates uses $ipaddresses, $server_name, $ports, $option
concat::fragment { "${instance_name}-peers-${peers_name}-${name}":
order => "30-peers-01-${peers_name}-${name}",
Expand Down
Loading