Debian Codegraph @

manifests/mailer.pp

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