| 1 |
# @summary |
| 2 |
# This type will setup a frontend service configuration block inside |
| 3 |
# the haproxy.cfg file on an haproxy load balancer. |
| 4 |
# |
| 5 |
# @note |
| 6 |
# Currently requires the puppetlabs/concat module on the Puppet Forge and |
| 7 |
# uses storeconfigs on the Puppet Server to export/collect resources |
| 8 |
# from all balancer members. |
| 9 |
# |
| 10 |
# @param section_name |
| 11 |
# This name goes right after the 'frontend' statement in haproxy.cfg |
| 12 |
# Default: $name (the namevar of the resource). |
| 13 |
# |
| 14 |
# @param ports |
| 15 |
# Ports on which the proxy will listen for connections on the ip address |
| 16 |
# specified in the ipaddress parameter. Accepts either a single |
| 17 |
# comma-separated string or an array of strings which may be ports or |
| 18 |
# hyphenated port ranges. |
| 19 |
# |
| 20 |
# @param bind |
| 21 |
# Set of ip addresses, port and bind options |
| 22 |
# $bind = { '10.0.0.1:80' => ['ssl', 'crt', '/path/to/my/crt.pem'] } |
| 23 |
# |
| 24 |
# @param ipaddress |
| 25 |
# The ip address the proxy binds to. |
| 26 |
# Empty addresses, '*', and '0.0.0.0' mean that the proxy listens |
| 27 |
# to all valid addresses on the system. |
| 28 |
# |
| 29 |
# @param mode |
| 30 |
# The mode of operation for the frontend service. Valid values are undef, |
| 31 |
# 'tcp', 'http', and 'health'. |
| 32 |
# |
| 33 |
# @param description |
| 34 |
# Allows to add a sentence to describe the related object in the HAProxy HTML |
| 35 |
# stats page. The description will be printed on the right of the object name |
| 36 |
# it describes. Usefull in huge environments |
| 37 |
# |
| 38 |
# @param bind_options |
| 39 |
# (Deprecated) An array of options to be specified after the bind declaration |
| 40 |
# in the listening serivce's configuration block. |
| 41 |
# |
| 42 |
# @param options |
| 43 |
# A hash of options that are inserted into the frontend service |
| 44 |
# configuration block. |
| 45 |
# |
| 46 |
# @param sort_options_alphabetic |
| 47 |
# Sort options either alphabetic or custom like haproxy internal sorts them. |
| 48 |
# Defaults to true. |
| 49 |
# |
| 50 |
# @param defaults |
| 51 |
# Name of the defaults section this backend will use. |
| 52 |
# Defaults to undef which means the global defaults section will be used. |
| 53 |
# |
| 54 |
# @param defaults_use_backend |
| 55 |
# If defaults are used and a default backend is configured use the backend |
| 56 |
# name for ordering. This means that the frontend is placed in the |
| 57 |
# configuration file before the backend configuration. |
| 58 |
# Defaults to true. |
| 59 |
# |
| 60 |
# @param config_file |
| 61 |
# Optional. Path of the config file where this entry will be added. |
| 62 |
# Assumes that the parent directory exists. |
| 63 |
# Default: $haproxy::params::config_file |
| 64 |
# |
| 65 |
# @param collect_exported |
| 66 |
# Boolean. Default true |
| 67 |
# |
| 68 |
# @param instance |
| 69 |
# Optional. Defaults to 'haproxy' |
| 70 |
# |
| 71 |
# @example |
| 72 |
# Exporting the resource for a balancer member: |
| 73 |
# |
| 74 |
# haproxy::frontend { 'puppet00': |
| 75 |
# ipaddress => $::ipaddress, |
| 76 |
# ports => [18140], |
| 77 |
# mode => 'tcp', |
| 78 |
# bind_options => 'accept-proxy', |
| 79 |
# options => { |
| 80 |
# 'option' => [ |
| 81 |
# 'tcplog', |
| 82 |
# 'accept-invalid-http-request', |
| 83 |
# ], |
| 84 |
# 'timeout client' => '30s', |
| 85 |
# 'balance' => 'roundrobin' |
| 86 |
# }, |
| 87 |
# } |
| 88 |
# |
| 89 |
# === Authors |
| 90 |
# |
| 91 |
# Gary Larizza <[email protected]> |
| 92 |
# |
| 93 |
define haproxy::frontend ( |
| 94 |
Optional[Haproxy::Ports] $ports = undef, |
| 95 |
Optional[Variant[String, Array]] $ipaddress = undef, |
| 96 |
Optional[Hash] $bind = undef, |
| 97 |
Optional[Enum['tcp', 'http', 'health']] $mode = undef, |
| 98 |
Boolean $collect_exported = true, |
| 99 |
Variant[Hash, Array[Hash]] $options = { |
| 100 |
'option' => [ |
| 101 |
'tcplog', |
| 102 |
], |
| 103 |
}, |
| 104 |
String $instance = 'haproxy', |
| 105 |
String[1] $section_name = $name, |
| 106 |
Boolean $sort_options_alphabetic = true, |
| 107 |
Optional[String] $description = undef, |
| 108 |
Optional[String] $defaults = undef, |
| 109 |
Boolean $defaults_use_backend = true, |
| 110 |
Optional[Stdlib::Absolutepath] $config_file = undef, |
| 111 |
# Deprecated |
| 112 |
Optional[Array] $bind_options = undef, |
| 113 |
) { |
| 114 |
if $ports and $bind { |
| 115 |
fail('The use of $ports and $bind is mutually exclusive, please choose either one') |
| 116 |
} |
| 117 |
if $ipaddress and $bind { |
| 118 |
fail('The use of $ipaddress and $bind is mutually exclusive, please choose either one') |
| 119 |
} |
| 120 |
if $bind_options { |
| 121 |
warning('The $bind_options parameter is deprecated; please use $bind instead') |
| 122 |
} |
| 123 |
|
| 124 |
include haproxy::params |
| 125 |
|
| 126 |
if $instance == 'haproxy' { |
| 127 |
$instance_name = 'haproxy' |
| 128 |
$_config_file = pick($config_file, $haproxy::config_file) |
| 129 |
} else { |
| 130 |
$instance_name = "haproxy-${instance}" |
| 131 |
$_config_file = pick($config_file, inline_template($haproxy::params::config_file_tmpl)) |
| 132 |
} |
| 133 |
|
| 134 |
include haproxy::globals |
| 135 |
$_sort_options_alphabetic = pick($sort_options_alphabetic, $haproxy::globals::sort_options_alphabetic) |
| 136 |
|
| 137 |
if $defaults == undef { |
| 138 |
$order = "15-${section_name}-00" |
| 139 |
} else { |
| 140 |
if $defaults_use_backend and 'default_backend' in $options { |
| 141 |
$order = "25-${defaults}-${options['default_backend']}-00-${section_name}" |
| 142 |
} else { |
| 143 |
$order = "25-${defaults}-${section_name}-00" |
| 144 |
} |
| 145 |
} |
| 146 |
|
| 147 |
$parameters = { |
| 148 |
'section_name' => $section_name, |
| 149 |
'bind' => $bind, |
| 150 |
'ipaddress' => $ipaddress, |
| 151 |
'ports' => $ports, |
| 152 |
'bind_options' => $bind_options, |
| 153 |
'mode' => $mode, |
| 154 |
'description' => $description, |
| 155 |
'options' => $options, |
| 156 |
'_sort_options_alphabetic' => $_sort_options_alphabetic, |
| 157 |
} |
| 158 |
|
| 159 |
# Template uses: $section_name, $ipaddress, $ports, $options |
| 160 |
concat::fragment { "${instance_name}-${section_name}_frontend_block": |
| 161 |
order => $order, |
| 162 |
target => $_config_file, |
| 163 |
content => epp('haproxy/haproxy_frontend_block.epp', $parameters), |
| 164 |
} |
| 165 |
} |