Debian Codegraph @

manifests/peer.pp

raw
1 # @summary This type will set up a peer entry inside the peers configuration block in haproxy.cfg on the load balancer.
2 #
3 # @note
4 # Currently, it has the ability to
5 # specify the instance name, ip address, ports and server_names.
6 #
7 #
8 # @param peers_name
9 # Specifies the peer in which this load balancer needs to be added.
10 #
11 # @param server_names
12 # Sets the name of the peer server in the peers configuration block.
13 # Defaults to the hostname. Can be an array. If this parameter is
14 # specified as an array, it must be the same length as the
15 # ipaddresses parameter's array. A peer is created for each pair
16 # of server\_names and ipaddresses in the array.
17 #
18 # @param ipaddresses
19 # Specifies the IP address used to contact the peer member server.
20 # Can be an array. If this parameter is specified as an array it
21 # must be the same length as the server\_names parameter's array.
22 # A peer is created for each pair of address and server_name.
23 #
24 # @param port
25 # Sets the port on which the peer is going to share the state.
26 #
27 # @param config_file
28 # Optional. Path of the config file where this entry will be added.
29 # Assumes that the parent directory exists.
30 # Default: $haproxy::params::config_file
31 #
32 # @param instance
33 # The instance name of the mailer entry. Default value: 'haproxy'.
34 #
35 # @note
36 # Automatic discovery of peer nodes may be implemented by exporting the peer resource
37 # for all HAProxy balancer servers that are configured in the same HA block and
38 # then collecting them on all load balancers.
39 #
40 define haproxy::peer (
41 String $peers_name,
42 Variant[String, Stdlib::Port] $port,
43 Variant[String[1], Array] $server_names = $facts['networking']['hostname'],
44 Variant[String, Array] $ipaddresses = $facts['networking']['ip'],
45 String $instance = 'haproxy',
46 Optional[Stdlib::Absolutepath] $config_file = undef,
47
48 ) {
49 include haproxy::params
50
51 if $instance == 'haproxy' {
52 $instance_name = 'haproxy'
53 $_config_file = pick($config_file, $haproxy::config_file)
54 } else {
55 $instance_name = "haproxy-${instance}"
56 $_config_file = pick($config_file, inline_template($haproxy::params::config_file_tmpl))
57 }
58
59 $parameters = {
60 'ipaddresses' => $ipaddresses,
61 'server_names' => $server_names,
62 'port' => $port,
63 }
64
65 # Templates uses $ipaddresses, $server_name, $ports, $option
66 concat::fragment { "${instance_name}-peers-${peers_name}-${name}":
67 order => "30-peers-01-${peers_name}-${name}",
68 target => $_config_file,
69 content => epp('haproxy/haproxy_peer.epp', $parameters),
70 }
71 }