Defined Type: haproxy::peer

Defined in:
manifests/peer.pp

Summary

This type will set up a peer entry inside the peers configuration block in haproxy.cfg on the load balancer.

Overview

Note:

Currently, it has the ability to specify the instance name, ip address, ports and server_names.

Note:

Automatic discovery of peer nodes may be implemented by exporting the peer resource for all HAProxy balancer servers that are configured in the same HA block and then collecting them on all load balancers.

Parameters:

  • peers_name (String)

    Specifies the peer in which this load balancer needs to be added.

  • server_names (Variant[String[1], Array]) (defaults to: $facts['networking']['hostname'])

    Sets the name of the peer server in the peers configuration block. Defaults to the hostname. Can be an array. If this parameter is specified as an array, it must be the same length as the ipaddresses parameter’s array. A peer is created for each pair of server_names and ipaddresses in the array.

  • ipaddresses (Variant[String, Array]) (defaults to: $facts['networking']['ip'])

    Specifies the IP address used to contact the peer member server. Can be an array. If this parameter is specified as an array it must be the same length as the server_names parameter’s array. A peer is created for each pair of address and server_name.

  • port (Variant[String, Stdlib::Port])

    Sets the port on which the peer is going to share the state.

  • config_file (Optional[Stdlib::Absolutepath]) (defaults to: undef)

    Optional. Path of the config file where this entry will be added. Assumes that the parent directory exists. Default: $haproxy::params::config_file

  • instance (String) (defaults to: 'haproxy')

    The instance name of the mailer entry. Default value: ‘haproxy’.



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'manifests/peer.pp', line 40

define haproxy::peer (
  String                          $peers_name,
  Variant[String, Stdlib::Port]   $port,
  Variant[String[1], Array]       $server_names = $facts['networking']['hostname'],
  Variant[String, Array]          $ipaddresses  = $facts['networking']['ip'],
  String                          $instance     = 'haproxy',
  Optional[Stdlib::Absolutepath]  $config_file  = undef,

) {
  include haproxy::params

  if $instance == 'haproxy' {
    $instance_name = 'haproxy'
    $_config_file = pick($config_file, $haproxy::config_file)
  } else {
    $instance_name = "haproxy-${instance}"
    $_config_file = pick($config_file, inline_template($haproxy::params::config_file_tmpl))
  }

  $parameters = {
    'ipaddresses'  => $ipaddresses,
    'server_names' => $server_names,
    'port'         => $port,
  }

  # Templates uses $ipaddresses, $server_name, $ports, $option
  concat::fragment { "${instance_name}-peers-${peers_name}-${name}":
    order   => "30-peers-01-${peers_name}-${name}",
    target  => $_config_file,
    content => epp('haproxy/haproxy_peer.epp', $parameters),
  }
}