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

Feature/make configvalidation configurable #238

Closed
wants to merge 9 commits into from
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -561,6 +561,10 @@ Main class, includes all other classes.

* `config_dir`: Path to the directory in which the main configuration file `haproxy.cfg` resides. Will also be used for storing any managed map files (see [`haproxy::mapfile`](#define-haproxymapfile). Default depends on platform.

* `config_validate`: Validate the HaProxy configuration before applying the changes. Requires the 'config_validate_path' variable. Default: 'true'.

* `config_validate_path`: Path to HaProxy validation script. Default: `/usr/sbin/haproxy -f %`.

#### Class: `haproxy::globals`

For global configuration options used by all haproxy instances.
Expand Down
21 changes: 16 additions & 5 deletions manifests/config.pp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
$config_dir = undef, # A default is required for Puppet 2.7 compatibility. When 2.7 is no longer supported, this parameter default should be removed.
$custom_fragment = undef, # A default is required for Puppet 2.7 compatibility. When 2.7 is no longer supported, this parameter default should be removed.
$merge_options = $haproxy::merge_options,
$config_validate = $haproxy::config_validate,
$config_validate_path = $haproxy::config_validate_path,
) {
if $caller_module_name != $module_name {
fail("Use of private class ${name} by ${caller_module_name}")
Expand Down Expand Up @@ -36,11 +38,20 @@
$_config_file = $haproxy::config_file
}

concat { $_config_file:
owner => '0',
group => '0',
mode => '0644',
validate_cmd => '/usr/sbin/haproxy -f %',

if $config_validate and $config_validate_path != undef {
concat { $_config_file:
owner => '0',
group => '0',
mode => '0644',
validate_cmd => $config_validate_path,
}
} else {
concat { $_config_file:
owner => '0',
group => '0',
mode => '0644',
}
}

# Simple Header
Expand Down
61 changes: 37 additions & 24 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,13 @@
# resides. Will also be used for storing any managed map files (see
# `haproxy::mapfile`). Default depends on platform.
#
# [*config_validate*]
# Boolean value to enable/disable config validation. Validation requires the
# 'config_validate_path'.
#
# [*config_validate_path*]
# Path to the HaProxy validation binary.
#
# === Examples
#
# class { 'haproxy':
Expand Down Expand Up @@ -102,18 +109,20 @@
# }
#
class haproxy (
$package_ensure = 'present',
$package_name = $haproxy::params::package_name,
$service_ensure = 'running',
$service_manage = true,
$service_options = $haproxy::params::service_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,
$package_ensure = 'present',
$package_name = $haproxy::params::package_name,
$service_ensure = 'running',
$service_manage = true,
$service_options = $haproxy::params::service_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,
$config_validate = $haproxy::params::config_validate,
$config_validate_path = $haproxy::params::config_validate_path,

# Deprecated
$manage_service = undef,
Expand All @@ -131,6 +140,8 @@
validate_string($service_options)
validate_hash($global_options, $defaults_options)
validate_absolute_path($config_dir)
validate_bool($config_validate)
validate_string($config_validate_path)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be validate_absolute_path


# NOTE: These deprecating parameters are implemented in this class,
# not in haproxy::instance. haproxy::instance is new and therefore
Expand Down Expand Up @@ -161,18 +172,20 @@
}

haproxy::instance{ $title:
package_ensure => $_package_ensure,
package_name => $package_name,
service_ensure => $_service_ensure,
service_manage => $_service_manage,
global_options => $global_options,
defaults_options => $defaults_options,
restart_command => $restart_command,
custom_fragment => $custom_fragment,
config_dir => $config_dir,
config_file => $config_file,
merge_options => $merge_options,
service_options => $service_options,
package_ensure => $_package_ensure,
package_name => $package_name,
service_ensure => $_service_ensure,
service_manage => $_service_manage,
global_options => $global_options,
defaults_options => $defaults_options,
restart_command => $restart_command,
custom_fragment => $custom_fragment,
config_dir => $config_dir,
config_file => $config_file,
merge_options => $merge_options,
service_options => $service_options,
config_validate => $config_validate,
config_validate_path => $config_validate_path,
}

}
50 changes: 31 additions & 19 deletions manifests/instance.pp
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,13 @@
# The parent directory will be created automatically.
# Defaults to undef.
#
#[*config_validate*]
# Boolean value to enable/disable config validation. Validation requires the
# 'config_validate_path'.
#
#[*config_validate_path*]
# Path to the HaProxy validation binary.
#
# === Examples
#
# A single instance of haproxy with all defaults
Expand Down Expand Up @@ -135,18 +142,20 @@
# 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,
$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,
$config_validate = $haproxy::params::config_validate,
$config_validate_path = $haproxy::params::config_validate_path,
) {

if $service_ensure != true and $service_ensure != false {
Expand Down Expand Up @@ -198,13 +207,16 @@
}

haproxy::config { $title:
instance_name => $instance_name,
config_dir => $_config_dir,
config_file => $_config_file,
global_options => $_global_options,
defaults_options => $_defaults_options,
custom_fragment => $custom_fragment,
merge_options => $merge_options,
instance_name => $instance_name,
config_dir => $_config_dir,
config_file => $_config_file,
global_options => $_global_options,
defaults_options => $_defaults_options,
custom_fragment => $custom_fragment,
merge_options => $merge_options,
config_validate => $config_validate,
config_validate_path => $config_validate_path,

}
haproxy::install { $title:
package_name => $package_name,
Expand Down
20 changes: 12 additions & 8 deletions manifests/params.pp
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,13 @@
'maxconn' => '8000'
}
# Single instance:
$config_dir = '/etc/haproxy'
$config_file = '/etc/haproxy/haproxy.cfg'
$config_dir = '/etc/haproxy'
$config_file = '/etc/haproxy/haproxy.cfg'
# Multi-instance:
$config_dir_tmpl = '/etc/<%= @instance_name %>'
$config_file_tmpl = "${config_dir_tmpl}/<%= @instance_name %>.cfg"
$config_dir_tmpl = '/etc/<%= @instance_name %>'
$config_file_tmpl = "${config_dir_tmpl}/<%= @instance_name %>.cfg"
$config_validate = true
$config_validate_path = '/usr/sbin/haproxy -f %'
}
'FreeBSD': {
$package_name = 'haproxy'
Expand Down Expand Up @@ -72,11 +74,13 @@
'srvtimeout' => '50000',
}
# Single instance:
$config_dir = '/usr/local/etc'
$config_file = '/usr/local/etc/haproxy.conf'
$config_dir = '/usr/local/etc'
$config_file = '/usr/local/etc/haproxy.conf'
# Multi-instance:
$config_dir_tmpl = '/usr/local/etc/<%= @instance_name %>'
$config_file_tmpl = "${config_dir_tmpl}/<%= @instance_name %>.conf"
$config_dir_tmpl = '/usr/local/etc/<%= @instance_name %>'
$config_file_tmpl = "${config_dir_tmpl}/<%= @instance_name %>.conf"
$config_validate = true
$config_validate_path = '/usr/sbin/haproxy -f %'
}
default: { fail("The ${::osfamily} operating system is not supported with the haproxy module") }
}
Expand Down