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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
|
# == Class: puppet-haproxy
#
# A Puppet module, using storeconfigs, to model an haproxy configuration.
# Currently VERY limited - assumes Redhat/CentOS setup. Pull requests accepted!
#
# === Requirement/Dependencies:
#
# Currently requires the ripienaar/concat module on the Puppet Forge and
# uses storeconfigs on the Puppet Master to export/collect resources
# from all balancer members.
#
# === Parameters
#
# [*enable*]
# Chooses whether haproxy should be installed or ensured absent.
# Currently ONLY accepts valid boolean true/false values.
#
# [*haproxy_global_options*]
# 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.
#
# [*haproxy_defaults_options*]
# 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.
#
#
# === Examples
#
# class { 'haproxy':
# enable => true,
# haproxy_global_options => { 'log' => "${::ipaddress} local0",
# 'chroot' => '/var/lib/haproxy',
# 'pidfile' => '/var/run/haproxy.pid',
# 'maxconn' => '4000',
# 'user' => 'haproxy',
# 'group' => 'haproxy',
# 'daemon' => '',
# 'stats' => 'socket /var/lib/haproxy/stats'
# },
# haproxy_defaults_options => { 'log' => 'global',
# 'stats' => 'enable',
# 'option' => 'redispatch',
# 'retries' => '3',
# 'timeout' => ['http-request 10s',
# 'queue 1m',
# 'connect 10s',
# 'client 1m',
# 'server 1m',
# 'check 10s'],
# 'maxconn' => '8000'
# },
#
# }
#
# === Authors
#
# Gary Larizza <gary@puppetlabs.com>
#
class haproxy (
$enable = true,
$haproxy_global_options = $haproxy::data::haproxy_global_options,
$haproxy_defaults_options = $haproxy::data::haproxy_defaults_options
) inherits haproxy::data {
include concat::setup
package { 'haproxy':
ensure => $enable ? {
true => present,
false => absent,
},
name => 'haproxy',
}
if $enable {
concat { '/etc/haproxy/haproxy.cfg':
owner => '0',
group => '0',
mode => '0644',
require => Package['haproxy'],
notify => Service['haproxy'],
}
# Simple Header
concat::fragment { '00-header':
target => '/etc/haproxy/haproxy.cfg',
order => '01',
content => "# This file managed by Puppet\n",
}
# Most of the variables are used inside the haproxy-base.cfg.erb template
concat::fragment { 'haproxy-base':
target => '/etc/haproxy/haproxy.cfg',
order => '10',
content => template('haproxy/haproxy-base.cfg.erb'),
}
if ($::operatingsystem == 'Ubuntu') {
file { '/etc/default/haproxy':
content => 'ENABLED=1',
require => Package['haproxy']
}
}
file { '/var/lib/haproxy':
ensure => directory,
before => Service['haproxy'],
}
}
service { 'haproxy':
ensure => $enable ? {
true => running,
false => stopped,
},
enable => $enable ? {
true => true,
false => false,
},
name => 'haproxy',
hasrestart => true,
hasstatus => true,
require => Concat['/etc/haproxy/haproxy.cfg'],
}
}
|