forked from glarizza/puppet-haproxy
-
Notifications
You must be signed in to change notification settings - Fork 267
/
config.pp
90 lines (82 loc) · 3.12 KB
/
config.pp
1
2
3
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
# @summary
# HAProxy configuration
# @api private
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, # A default is required for Puppet 2.7 compatibility. When 2.7 is no longer supported, this parameter default should be removed.
Optional[String] $custom_fragment = undef, # A default is required for Puppet 2.7 compatibility. When 2.7 is no longer supported, this parameter default should be removed. << Update 15/12/22 This still needs a default.
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 = merge($haproxy::params::global_options, $global_options)
$_defaults_options = merge($haproxy::params::defaults_options, $defaults_options)
} else {
$_global_options = $global_options
$_defaults_options = $defaults_options
warning("${module_name}: The \$merge_options parameter will default to true in the next major release. Please review the documentation regarding the implications.") # lint:ignore:140chars
}
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",
}
# Template uses $_global_options, $_defaults_options, $custom_fragment
concat::fragment { "${instance_name}-haproxy-base":
target => $_config_file,
order => '10',
content => template("${module_name}/haproxy-base.cfg.erb"),
}
}
if $chroot_dir_manage {
if $_global_options['chroot'] {
file { $_global_options['chroot']:
ensure => directory,
owner => $_global_options['user'],
group => $_global_options['group'],
}
}
}
}