Defined Type: haproxy::config

Defined in:
manifests/config.pp

Summary

HAProxy configuration

Overview

Parameters:

  • package_ensure (Variant[Enum['present', 'absent', 'purged', 'disabled', 'installed', 'latest'], String[1]])
  • instance_name (String)
  • config_file (Stdlib::Absolutepath)
  • global_options (Hash)
  • defaults_options (Hash)
  • chroot_dir_manage (Boolean)
  • config_dir (Stdlib::Absolutepath) (defaults to: undef)
  • custom_fragment (Optional[String]) (defaults to: undef)
  • merge_options (Boolean) (defaults to: $haproxy::merge_options)
  • config_validate_cmd (Variant[Stdlib::Absolutepath, String]) (defaults to: $haproxy::config_validate_cmd)


4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'manifests/config.pp', line 4

define haproxy::config (
  # lint:ignore:140chars
  Variant[Enum['present', 'absent', 'purged', 'disabled', 'installed', 'latest'], String[1]] $package_ensure,
  String                                $instance_name,
  Stdlib::Absolutepath                  $config_file,
  Hash                                  $global_options,
  Hash                                  $defaults_options,
  Boolean                               $chroot_dir_manage,
  Stdlib::Absolutepath                  $config_dir          = undef,
  Optional[String]                      $custom_fragment     = undef,
  Boolean                               $merge_options       = $haproxy::merge_options,
  Variant[Stdlib::Absolutepath, String] $config_validate_cmd = $haproxy::config_validate_cmd,
  # lint:endignore
) {
  if $caller_module_name != $module_name {
    fail("Use of private class ${name} by ${caller_module_name}")
  }

  if $merge_options {
    $_global_options   = $haproxy::params::global_options + $global_options
    $_defaults_options = $haproxy::params::defaults_options + $defaults_options
  } else {
    $_global_options   = $global_options
    $_defaults_options = $defaults_options
  }

  if defined(Class['haproxy']) {
    $manage_config_dir = $haproxy::manage_config_dir
  } else {
    $manage_config_dir = $haproxy::params::manage_config_dir
  }
  if $manage_config_dir {
    if $config_dir != undef {
      file { $config_dir:
        ensure => directory,
        owner  => '0',
        group  => '0',
        mode   => '0755',
      }
    }
  }

  if $config_file != undef {
    $_config_file = $config_file
  } else {
    $_config_file = $haproxy::config_file
  }

  if $package_ensure == 'absent' {
    file { $_config_file: ensure => absent }
  } else {
    concat { $_config_file:
      owner => '0',
      group => '0',
      mode  => '0640',
    }

    Concat[$_config_file] {
      validate_cmd => $config_validate_cmd,
    }

    # Simple Header
    concat::fragment { "${instance_name}-00-header":
      target  => $_config_file,
      order   => '01',
      content => "# This file is managed by Puppet\n",
    }

    $parameters = {
      '_global_options'   => $_global_options,
      '_defaults_options' => $_defaults_options,
      'custom_fragment'   => $custom_fragment,
    }

    # Template uses $_global_options, $_defaults_options, $custom_fragment
    concat::fragment { "${instance_name}-haproxy-base":
      target  => $_config_file,
      order   => '10',
      content => epp("${module_name}/haproxy-base.cfg.epp", $parameters),
    }
  }

  if $chroot_dir_manage {
    if $_global_options['chroot'] {
      file { $_global_options['chroot']:
        ensure => directory,
        owner  => $_global_options['user'],
        group  => $_global_options['group'],
      }
    }
  }
}