| 1 |
# @summary |
| 2 |
# This type will setup a additional defaults configuration block inside the |
| 3 |
# haproxy.cfg file on an haproxy load balancer. |
| 4 |
# |
| 5 |
# @note |
| 6 |
# A new default configuration block resets all defaults of prior defaults configuration blocks. |
| 7 |
# Listener, Backends, Frontends and Balancermember can be configured behind a default |
| 8 |
# configuration block by setting the defaults parameter to the corresponding |
| 9 |
# defaults name. |
| 10 |
# |
| 11 |
# |
| 12 |
# @param options |
| 13 |
# A hash of options that are inserted into the defaults configuration block. |
| 14 |
# |
| 15 |
# @param sort_options_alphabetic |
| 16 |
# Sort options either alphabetic or custom like haproxy internal sorts them. |
| 17 |
# Defaults to true. |
| 18 |
# |
| 19 |
# @param merge_options |
| 20 |
# Whether to merge the user-supplied `options` hash with the |
| 21 |
# `default_options` values set in params.pp. Merging allows to change |
| 22 |
# or add options without having to recreate the entire hash. |
| 23 |
# |
| 24 |
# @param instance |
| 25 |
# Optional. Defaults to 'haproxy'. |
| 26 |
# |
| 27 |
define haproxy::defaults ( |
| 28 |
Hash $options = {}, |
| 29 |
Boolean $sort_options_alphabetic = true, |
| 30 |
Boolean $merge_options = $haproxy::params::merge_options, |
| 31 |
String $instance = 'haproxy', |
| 32 |
) { |
| 33 |
if $instance == 'haproxy' { |
| 34 |
include haproxy |
| 35 |
$instance_name = 'haproxy' |
| 36 |
$config_file = $haproxy::config_file |
| 37 |
} else { |
| 38 |
include haproxy::params |
| 39 |
$instance_name = "haproxy-${instance}" |
| 40 |
$config_file = inline_template($haproxy::params::config_file_tmpl) |
| 41 |
} |
| 42 |
include haproxy::globals |
| 43 |
$_sort_options_alphabetic = pick($sort_options_alphabetic, $haproxy::globals::sort_options_alphabetic) |
| 44 |
|
| 45 |
$defaults_options = pick($options, $haproxy::params::defaults_options) |
| 46 |
if $merge_options { |
| 47 |
$_defaults_options = $haproxy::params::defaults_options + $defaults_options |
| 48 |
} else { |
| 49 |
$_defaults_options = $defaults_options |
| 50 |
} |
| 51 |
|
| 52 |
$parameters = { |
| 53 |
'_sort_options_alphabetic' => $_sort_options_alphabetic, |
| 54 |
'options' => $_defaults_options, |
| 55 |
'name' => $name, |
| 56 |
} |
| 57 |
|
| 58 |
concat::fragment { "${instance_name}-${name}_defaults_block": |
| 59 |
order => "25-${name}", |
| 60 |
target => $config_file, |
| 61 |
content => epp('haproxy/haproxy_defaults_block.epp', $parameters), |
| 62 |
} |
| 63 |
} |