| 1 |
# @summary |
| 2 |
# This type will setup resolvers 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 |
# |
| 11 |
# @param section_name |
| 12 |
# This name goes right after the 'resolvers' statement in haproxy.cfg |
| 13 |
# Default: $name (the namevar of the resource). |
| 14 |
# |
| 15 |
# @param nameservers |
| 16 |
# Set of id, ip addresses and port options. |
| 17 |
# $nameservers = { 'dns1' => '10.0.0.1:53', 'dns2' => '10.0.0.2:53' } |
| 18 |
# Either the 'nameservers' or the 'parse_resolv_conf' parameter must be |
| 19 |
# specified in order for the resolver to work. |
| 20 |
# Default: none specified. |
| 21 |
# |
| 22 |
# @param parse_resolv_conf |
| 23 |
# If true, parse resolv.conf to retrieve an ordered set of nameservers. |
| 24 |
# This can be used instead of (or in addition to) the 'nameservers' |
| 25 |
# parameter. |
| 26 |
# Default: false |
| 27 |
# |
| 28 |
# @param hold |
| 29 |
# Defines <period> during which the last name resolution should be kept |
| 30 |
# based on last valid resolution status. |
| 31 |
# $hold = { 'nx' => '30s', 'valid' => '10s' } |
| 32 |
# |
| 33 |
# @param resolve_retries |
| 34 |
# Defines the number <nb> of queries to send to resolve a server name before |
| 35 |
# giving up. |
| 36 |
# $resolve_retries = 3 |
| 37 |
# |
| 38 |
# @param timeout |
| 39 |
# Defines timeouts related to name resolution in the listening serivce's |
| 40 |
# configuration block. |
| 41 |
# $timeout = { 'retry' => '1s' } |
| 42 |
# |
| 43 |
# @param accepted_payload_size |
| 44 |
# Defines the maximum payload size accepted by HAProxy and announced to all the |
| 45 |
# name servers configured in this resolvers section. |
| 46 |
# <nb> is in bytes. If not set, HAProxy announces 512. (minimal value defined |
| 47 |
# by RFC 6891) |
| 48 |
# Note: the maximum allowed value is 8192. |
| 49 |
# |
| 50 |
# @param collect_exported |
| 51 |
# Boolean, default 'true'. True means 'collect exported @@balancermember |
| 52 |
# resources' (for the case when every balancermember node exports itself), |
| 53 |
# false means 'rely on the existing declared balancermember resources' (for |
| 54 |
# the case when you know the full set of balancermember in advance and use |
| 55 |
# haproxy::balancermember with array arguments, which allows you to deploy |
| 56 |
# everything in 1 run) |
| 57 |
# |
| 58 |
# @param config_file |
| 59 |
# Optional. Path of the config file where this entry will be added. |
| 60 |
# Assumes that the parent directory exists. |
| 61 |
# Default: $haproxy::params::config_file |
| 62 |
# |
| 63 |
# @param sort_options_alphabetic |
| 64 |
# Sort options either alphabetic or custom like haproxy internal sorts them. |
| 65 |
# Defaults to true. |
| 66 |
# |
| 67 |
# @param defaults |
| 68 |
# Name of the defaults section this backend will use. |
| 69 |
# Defaults to undef which means the global defaults section will be used. |
| 70 |
# |
| 71 |
# @param instance |
| 72 |
# Optional. Defaults to 'haproxy' |
| 73 |
# |
| 74 |
# @example |
| 75 |
# Exporting the resource for a balancer member: |
| 76 |
# |
| 77 |
# haproxy::resolver { 'puppet00': |
| 78 |
# nameservers => { |
| 79 |
# 'dns1' => '10.0.0.1:53', |
| 80 |
# 'dns2' => '10.0.0.2:53' |
| 81 |
# }, |
| 82 |
# hold => { |
| 83 |
# 'nx' => '30s', |
| 84 |
# 'valid' => '10s' |
| 85 |
# }, |
| 86 |
# resolve_retries => 3, |
| 87 |
# timeout => { |
| 88 |
# 'retry' => '1s' |
| 89 |
# }, |
| 90 |
# accepted_payload_size => 512, |
| 91 |
# } |
| 92 |
# |
| 93 |
# === Authors |
| 94 |
# |
| 95 |
# Gary Larizza <[email protected]> |
| 96 |
# Ricardo Rosales <[email protected]> |
| 97 |
# |
| 98 |
define haproxy::resolver ( |
| 99 |
Hash $nameservers = {}, |
| 100 |
Boolean $parse_resolv_conf = false, |
| 101 |
Optional[Hash] $hold = undef, |
| 102 |
Optional[Integer] $resolve_retries = undef, |
| 103 |
Optional[Hash] $timeout = undef, |
| 104 |
# https://cbonte.github.io/haproxy-dconv/1.8/configuration.html#5.3.2-accepted_payload_size |
| 105 |
Optional[Integer[512, 8192]] $accepted_payload_size = undef, |
| 106 |
String $instance = 'haproxy', |
| 107 |
String[1] $section_name = $name, |
| 108 |
Boolean $sort_options_alphabetic = true, |
| 109 |
Boolean $collect_exported = true, |
| 110 |
Optional[Stdlib::Absolutepath] $config_file = undef, |
| 111 |
Optional[String] $defaults = undef, |
| 112 |
) { |
| 113 |
include haproxy::params |
| 114 |
|
| 115 |
if $instance == 'haproxy' { |
| 116 |
$instance_name = 'haproxy' |
| 117 |
$_config_file = pick($config_file, $haproxy::config_file) |
| 118 |
} else { |
| 119 |
$instance_name = "haproxy-${instance}" |
| 120 |
$_config_file = pick($config_file, inline_template($haproxy::params::config_file_tmpl)) |
| 121 |
} |
| 122 |
|
| 123 |
assert_type(Stdlib::AbsolutePath, dirname($_config_file)) |
| 124 |
|
| 125 |
include haproxy::globals |
| 126 |
$_sort_options_alphabetic = pick($sort_options_alphabetic, $haproxy::globals::sort_options_alphabetic) |
| 127 |
|
| 128 |
if $defaults == undef { |
| 129 |
$order = "20-${section_name}-01" |
| 130 |
} else { |
| 131 |
$order = "25-${defaults}-${section_name}-02" |
| 132 |
} |
| 133 |
|
| 134 |
$parameters = { |
| 135 |
'section_name' => $section_name, |
| 136 |
'nameservers' => $nameservers, |
| 137 |
'parse_resolv_conf' => $parse_resolv_conf, |
| 138 |
'resolve_retries' => $resolve_retries, |
| 139 |
'timeout' => $timeout, |
| 140 |
'hold' => $hold, |
| 141 |
'accepted_payload_size' => $accepted_payload_size, |
| 142 |
} |
| 143 |
# Template uses: $section_name |
| 144 |
concat::fragment { "${instance_name}-${section_name}_resolver_block": |
| 145 |
order => $order, |
| 146 |
target => $_config_file, |
| 147 |
content => epp('haproxy/haproxy_resolver_block.epp', $parameters), |
| 148 |
} |
| 149 |
|
| 150 |
if $collect_exported { |
| 151 |
haproxy::balancermember::collect_exported { $section_name: } |
| 152 |
} |
| 153 |
# else: the resources have been created and they introduced their |
| 154 |
# concat fragments. We don't have to do anything about them. |
| 155 |
} |