Defined Type: haproxy::instance

Defined in:
manifests/instance.pp

Summary

Manages haproxy permitting multiple instances to run on the same machine.

Overview

template() function). Defaults to undef

Note:

Normally users use the Class, which runs a single haproxy daemon on a machine.

Note:

Currently requires the puppetlabs/concat module on the Puppet Forge and uses storeconfigs on the Puppet Server to export/collect resources from all balancer members.

Note:

When running multiple instances on one host, there must be a Service[] for each instance. One way to create the situation where Service[] works is using haproxy::instance_service. However you may want to do it some other way. For example, you may not have packages for your custom haproxy binary. Or, you may wish to use the standard haproxy package but not create links to it, or you may have different init.d scripts. In these cases, write your own puppet code that will result in Service[] working for you and do not call haproxy::instance_service.

Examples:

A single instance of haproxy with all defaults
i.e. emulate Class['haproxy']
 package{ 'haproxy': ensure => present }->haproxy::instance { 'haproxy': }->
 haproxy::listen { 'puppet00':
   instance         => 'haproxy',
   collect_exported => false,
   ipaddress        => $::ipaddress,
   ports            => '8140',
 }
Multiple instances of haproxy:
 haproxy::instance { 'group1': }
 haproxy::instance_service { 'group1':
   haproxy_init_source => "puppet:///modules/${module_name}/haproxy-group1.init",
 }
 haproxy::listen { 'puppet00':
   instance         => 'group1',
   collect_exported => false,
   ipaddress        => $::ipaddress,
   ports            => '8800',
   requires         => Package['haproxy'],
 }
 haproxy::instance { 'group2': }
 haproxy::instance_service { 'group2':
   haproxy_init_source => "puppet:///modules/${module_name}/haproxy-group1.init",
 }
 haproxy::listen { 'puppet00':
   instance         => 'group2',
   collect_exported => false,
   ipaddress        => $::ipaddress,
   ports            => '9900',
   requires         => Package['haproxy'],
 }
Multiple instances of haproxy, one with a custom haproxy package:
 haproxy::instance { 'group1': }
 haproxy::instance_service { 'group1':
   haproxy_init_source => "puppet:///modules/${module_name}/haproxy-group1.init",
 }
 haproxy::listen { 'puppet00':
   instance         => 'group1',
   collect_exported => false,
   ipaddress        => $::ipaddress,
   ports            => '8800',
   requires         => Package['haproxy'],
 }
 haproxy::instance { 'group2': }
 haproxy::instance_service { 'group2':
   haproxy_package     => 'custom_haproxy',
   haproxy_init_source => "puppet:///modules/${module_name}/haproxy-group2.init",
 }
 haproxy::listen { 'puppet00':
   instance         => 'group2',
   collect_exported => false,
   ipaddress        => $::ipaddress,
   ports            => '9900',
   requires         => Package['haproxy'],
 }

Parameters:

  • package_ensure (Variant[Enum['present', 'absent', 'purged', 'disabled', 'installed', 'latest'], String[1]]) (defaults to: 'present')

    Ensure the package is present (installed), absent or a specific version. Defaults to ‘present’

  • package_name (Optional[String]) (defaults to: undef)

    The package name of haproxy. Defaults to undef, and no package is installed. NOTE: Class has a different default.

  • service_ensure (Variant[Enum['running', 'stopped'], Boolean]) (defaults to: 'running')

    Chooses whether the haproxy service should be running & enabled at boot, or stopped and disabled at boot. Defaults to ‘running’

  • service_manage (Boolean) (defaults to: true)

    Chooses whether the haproxy service state should be managed by puppet at all. Defaults to true

  • chroot_dir_manage (Boolean) (defaults to: true)

    Chooses whether the haproxy chroot directory should be managed by puppet at all. Defaults to true

  • service_name (Optional[String]) (defaults to: undef)

    The service name for haproxy. Defaults to undef. If no name is given then the value computed for $instance_name will be used. NOTE: Class has a different default.

  • global_options (Optional[Hash]) (defaults to: undef)

    A hash of all the haproxy global options. If you want to specify more

    than one option (i.e. multiple timeout or stats options), pass those
    options as an array and you will get a line for each of them in the
    resultant haproxy.cfg file.
    
  • defaults_options (Optional[Hash]) (defaults to: undef)

    A hash of all the haproxy defaults options. If you want to specify more

    than one option (i.e. multiple timeout or stats options), pass those
    options as an array and you will get a line for each of them in the
    resultant haproxy.cfg file.
    
  • restart_command (Optional[String]) (defaults to: undef)

    Command to use when restarting the on config changes.

    Passed directly as the <code>'restart'</code> parameter to the service
    resource.  #    Defaults to undef i.e. whatever the service default is.
    
  • custom_fragment (Optional[String]) (defaults to: undef)

    Allows arbitrary HAProxy configuration to be passed through to support additional configuration not available via parameters, or to short-circuit the defined resources such as haproxy::listen when an operater would rather just write plain configuration. Accepts a string (ie, output from the

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

    Allows arbitrary config filename to be specified. If this is used, it is assumed that the directory path to the file exists and has owner/group/permissions as desired. If set to undef, the name will be generated as follows:

    If $title is 'haproxy', the operating system default will be used.
    Otherwise, /etc/haproxy-$title/haproxy-$title.conf (Linux),
    or /usr/local/etc/haproxy-$title/haproxy-$title.conf (FreeBSD)
    The parent directory will be created automatically.
    

    Defaults to undef.

  • config_validate_cmd (Variant[Stdlib::Absolutepath, String]) (defaults to: $haproxy::params::config_validate_cmd)

    Command used by concat validate_cmd to validate new config file concat is a valid haproxy config. Default /usr/sbin/haproxy -f % -c

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

    Optional. Default undef.

  • merge_options (Boolean) (defaults to: $haproxy::params::merge_options)
  • service_options (String) (defaults to: $haproxy::params::service_options)
  • sysconfig_options (String) (defaults to: $haproxy::params::sysconfig_options)


161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
# File 'manifests/instance.pp', line 161

define haproxy::instance (
  Variant[Enum['present', 'absent', 'purged', 'disabled', 'installed', 'latest'], String[1]] $package_ensure = 'present',
  Optional[String]                             $package_name         = undef,
  Variant[Enum['running', 'stopped'], Boolean] $service_ensure       = 'running',
  Boolean                                      $service_manage       = true,
  Boolean                                      $chroot_dir_manage    = true,
  Optional[String]                             $service_name         = undef,
  Optional[Hash]                               $global_options       = undef,
  Optional[Hash]                               $defaults_options     = undef,
  Optional[String]                             $restart_command      = undef,
  Optional[String]                             $custom_fragment      = undef,
  Optional[Stdlib::Absolutepath]               $config_dir           = undef,
  Optional[Stdlib::Absolutepath]               $config_file          = undef,
  Variant[Stdlib::Absolutepath, String]        $config_validate_cmd  = $haproxy::params::config_validate_cmd,
  Boolean                                      $merge_options        = $haproxy::params::merge_options,
  String                                       $service_options      = $haproxy::params::service_options,
  String                                       $sysconfig_options    = $haproxy::params::sysconfig_options,
) {
  # Since this is a 'define', we can not use 'inherts haproxy::params'.
  # Therefore, we "include haproxy::params" for any parameters we need.
  contain haproxy::params

  $_global_options = pick($global_options, $haproxy::params::global_options)
  $_defaults_options = pick($defaults_options, $haproxy::params::defaults_options)

  # Determine instance_name based on:
  #   single-instance hosts: haproxy
  #   multi-instance hosts:  haproxy-$title
  if $title == 'haproxy' {
    $instance_name = 'haproxy'
  } else {
    $instance_name = "haproxy-${title}"
  }

  # Determine config_dir and config_file:
  #   If config_dir defined, use it.  Otherwise:
  #   single-instance hosts: use defaults
  #   multi-instance hosts:  use templates
  if $instance_name == 'haproxy' {
    $_config_file = pick($config_file, $haproxy::params::config_file)
  } else {
    $_config_file = pick($config_file, inline_template($haproxy::params::config_file_tmpl))
  }

  if $instance_name == 'haproxy' {
    $_config_dir = pick($config_dir, $haproxy::params::config_dir)
  } else {
    $_config_dir = pick($config_dir, inline_template($haproxy::params::config_dir_tmpl))
  }

  $instance_service_name = pick($service_name, $instance_name)

  haproxy::config { $title:
    instance_name       => $instance_name,
    config_dir          => $_config_dir,
    config_file         => $_config_file,
    global_options      => $_global_options,
    defaults_options    => $_defaults_options,
    custom_fragment     => $custom_fragment,
    merge_options       => $merge_options,
    package_ensure      => $package_ensure,
    chroot_dir_manage   => $chroot_dir_manage,
    config_validate_cmd => $config_validate_cmd,
  }
  haproxy::install { $title:
    package_name   => $package_name,
    package_ensure => $package_ensure,
  }
  haproxy::service { $title:
    instance_name     => $instance_service_name,
    service_ensure    => $service_ensure,
    service_manage    => $service_manage,
    restart_command   => $restart_command,
    service_options   => $service_options,
    sysconfig_options => $sysconfig_options,
  }

  if $package_ensure == 'absent' or $package_ensure == 'purged' {
    Haproxy::Service[$title]
    -> Haproxy::Config[$title]
    -> Haproxy::Install[$title]
  } else {
    Haproxy::Install[$title]
    -> Haproxy::Config[$title]
    ~> Haproxy::Service[$title]
  }
}