Skip to content

Commit 8adbf88

Browse files
committed
Add haproxy::instance for the creation of multiple instances of haproxy on a host. See [MODULES-1783]
* New Define Resource Type: haproxy::instance * New Define Resource Type: haproxy::instance_service * Class[haproxy] is now a wrapper that calls haproxy::instance * Add "instance" parameter to all public defines. * All private classes become private defined resource types. * "inherts params" no longer used for classes that are now defines * Documentation updated, examples added * Spec tests updated and new tests added * Upgrade to stdlib 3.2.0 * Upgrade to concat 1.2.3
1 parent 6bca1f0 commit 8adbf88

38 files changed

+1919
-214
lines changed

.fixtures.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@ fixtures:
55
ref: '1.2.3'
66
stdlib:
77
repo: "git://github.com/puppetlabs/puppetlabs-stdlib.git"
8-
ref: '2.4.0'
8+
ref: '3.2.0'
99
symlinks:
1010
haproxy: "#{source_dir}"

CHANGELOG.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
## 2015-07-15 - Supported Release 1.3.0
2+
### Summary
3+
This release adds puppet 4 support, and adds the ability to specify the order
4+
of option entries for `haproxy::frontend` and `haproxy::listen` defined
5+
resources.
6+
7+
#### Features
8+
- Adds puppet 4 compatibility
9+
- Updated readme
10+
- Gentoo compatibility
11+
- Suse compatibility
12+
- Add ability for frontend and listen to be ordered
13+
14+
115
##2015-03-10 - Supported Release 1.2.0
216
###Summary
317
This release adds flexibility for configuration of balancermembers and bind settings, and adds support for configuring peers. This release also renames the `tests` directory to `examples`

Gemfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ group :system_tests do
2828
gem 'beaker-rspec', :require => false
2929
end
3030
gem 'serverspec', :require => false
31+
gem 'beaker-puppet_install_helper', :require => false
3132
end
3233

3334

README.md

Lines changed: 279 additions & 36 deletions
Large diffs are not rendered by default.

manifests/backend.pp

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@
1515
#
1616
# === Parameters
1717
#
18-
# [*name*]
19-
# The namevar of the defined resource type is the backend service's name.
18+
# [*section_name*]
2019
# This name goes right after the 'backend' statement in haproxy.cfg
20+
# Default: $name (the namevar of the resource).
2121
#
2222
# [*options*]
2323
# A hash of options that are inserted into the backend configuration block.
@@ -57,22 +57,32 @@
5757
'ssl-hello-chk'
5858
],
5959
'balance' => 'roundrobin'
60-
}
60+
},
61+
$instance = 'haproxy',
62+
$section_name = $name,
6163
) {
64+
if defined(Haproxy::Listen[$section_name]) {
65+
fail("An haproxy::listen resource was discovered with the same name (${section_name}) which is not supported")
66+
}
6267

63-
if defined(Haproxy::Listen[$name]) {
64-
fail("An haproxy::listen resource was discovered with the same name (${name}) which is not supported")
68+
include haproxy::params
69+
if $instance == 'haproxy' {
70+
$instance_name = 'haproxy'
71+
$config_file = $haproxy::params::config_file
72+
} else {
73+
$instance_name = "haproxy-${instance}"
74+
$config_file = inline_template($haproxy::params::config_file_tmpl)
6575
}
6676

67-
# Template uses: $name, $ipaddress, $ports, $options
68-
concat::fragment { "${name}_backend_block":
69-
order => "20-${name}-00",
70-
target => $::haproxy::config_file,
77+
# Template uses: $section_name, $ipaddress, $ports, $options
78+
concat::fragment { "${instance_name}-${section_name}_backend_block":
79+
order => "20-${section_name}-00",
80+
target => $config_file,
7181
content => template('haproxy/haproxy_backend_block.erb'),
7282
}
7383

7484
if $collect_exported {
75-
haproxy::balancermember::collect_exported { $name: }
85+
haproxy::balancermember::collect_exported { $section_name: }
7686
}
7787
# else: the resources have been created and they introduced their
7888
# concat fragments. We don't have to do anything about them.

manifests/balancermember.pp

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,6 @@
1616
#
1717
# === Parameters
1818
#
19-
# [*name*]
20-
# The title of the resource is arbitrary and only utilized in the concat
21-
# fragment name.
22-
#
2319
# [*listening_service*]
2420
# The haproxy service's instance name (or, the title of the
2521
# haproxy::listen resource). This must match up with a declared
@@ -93,14 +89,24 @@
9389
$ipaddresses = $::ipaddress,
9490
$ensure = 'present',
9591
$options = '',
96-
$define_cookies = false
92+
$define_cookies = false,
93+
$instance = 'haproxy',
9794
) {
9895

96+
include haproxy::params
97+
if $instance == 'haproxy' {
98+
$instance_name = 'haproxy'
99+
$config_file = $haproxy::params::config_file
100+
} else {
101+
$instance_name = "haproxy-${instance}"
102+
$config_file = inline_template($haproxy::params::config_file_tmpl)
103+
}
104+
99105
# Template uses $ipaddresses, $server_name, $ports, $option
100-
concat::fragment { "${listening_service}_balancermember_${name}":
106+
concat::fragment { "${instance_name}-${listening_service}_balancermember_${name}":
101107
ensure => $ensure,
102108
order => "20-${listening_service}-01-${name}",
103-
target => $::haproxy::config_file,
109+
target => $config_file,
104110
content => template('haproxy/haproxy_balancermember.erb'),
105111
}
106112
}

manifests/config.pp

Lines changed: 44 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,66 @@
11
# Private class
2-
class haproxy::config inherits haproxy {
2+
define haproxy::config (
3+
$instance_name,
4+
$config_file,
5+
$global_options,
6+
$defaults_options,
7+
$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.
8+
$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.
9+
$merge_options = $haproxy::merge_options,
10+
) {
311
if $caller_module_name != $module_name {
412
fail("Use of private class ${name} by ${caller_module_name}")
513
}
614

7-
concat { $haproxy::config_file:
15+
if $merge_options {
16+
$_global_options = merge($haproxy::params::global_options, $global_options)
17+
$_defaults_options = merge($haproxy::params::defaults_options, $defaults_options)
18+
} else {
19+
$_global_options = $global_options
20+
$_defaults_options = $defaults_options
21+
warning("${module_name}: The \$merge_options parameter will default to true in the next major release. Please review the documentation regarding the implications.")
22+
}
23+
24+
if $config_dir != undef {
25+
file { $config_dir:
26+
ensure => directory,
27+
owner => 'root',
28+
group => 'root',
29+
mode => '0755',
30+
}
31+
}
32+
33+
if $config_file != undef {
34+
$_config_file = $config_file
35+
} else {
36+
$_config_file = $haproxy::config_file
37+
}
38+
39+
concat { $_config_file:
840
owner => '0',
941
group => '0',
1042
mode => '0644',
1143
}
1244

1345
# Simple Header
14-
concat::fragment { '00-header':
15-
target => $haproxy::config_file,
46+
concat::fragment { "${instance_name}-00-header":
47+
target => $config_file,
1648
order => '01',
1749
content => "# This file managed by Puppet\n",
1850
}
1951

20-
# Template uses $global_options, $defaults_options
21-
concat::fragment { 'haproxy-base':
22-
target => $haproxy::config_file,
52+
# Template uses $_global_options, $_defaults_options, $custom_fragment
53+
concat::fragment { "${instance_name}-haproxy-base":
54+
target => $config_file,
2355
order => '10',
24-
content => template('haproxy/haproxy-base.cfg.erb'),
56+
content => template("${module_name}/haproxy-base.cfg.erb"),
2557
}
2658

27-
if $haproxy::global_options['chroot'] {
28-
file { $haproxy::global_options['chroot']:
59+
if $_global_options['chroot'] {
60+
file { $_global_options['chroot']:
2961
ensure => directory,
30-
owner => $haproxy::global_options['user'],
31-
group => $haproxy::global_options['group'],
62+
owner => $_global_options['user'],
63+
group => $_global_options['group'],
3264
}
3365
}
3466
}

manifests/frontend.pp

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111
#
1212
# === Parameters
1313
#
14-
# [*name*]
15-
# The namevar of the defined resource type is the frontend service's name.
14+
# [*section_name*]
1615
# This name goes right after the 'frontend' statement in haproxy.cfg
16+
# Default: $name (the namevar of the resource).
1717
#
1818
# [*ports*]
1919
# Ports on which the proxy will listen for connections on the ip address
@@ -56,7 +56,7 @@
5656
# 'tcplog',
5757
# 'accept-invalid-http-request',
5858
# ],
59-
# 'timeout client' => '30',
59+
# 'timeout client' => '30s',
6060
# 'balance' => 'roundrobin'
6161
# },
6262
# }
@@ -76,10 +76,11 @@
7676
'tcplog',
7777
],
7878
},
79+
$instance = 'haproxy',
80+
$section_name = $name,
7981
# Deprecated
80-
$bind_options = '',
82+
$bind_options = undef,
8183
) {
82-
8384
if $ports and $bind {
8485
fail('The use of $ports and $bind is mutually exclusive, please choose either one')
8586
}
@@ -92,10 +93,20 @@
9293
if $bind {
9394
validate_hash($bind)
9495
}
95-
# Template uses: $name, $ipaddress, $ports, $options
96-
concat::fragment { "${name}_frontend_block":
97-
order => "15-${name}-00",
98-
target => $::haproxy::config_file,
96+
97+
include haproxy::params
98+
if $instance == 'haproxy' {
99+
$instance_name = 'haproxy'
100+
$config_file = $haproxy::params::config_file
101+
} else {
102+
$instance_name = "haproxy-${instance}"
103+
$config_file = inline_template($haproxy::params::config_file_tmpl)
104+
}
105+
106+
# Template uses: $section_name, $ipaddress, $ports, $options
107+
concat::fragment { "${instance_name}-${section_name}_frontend_block":
108+
order => "15-${section_name}-00",
109+
target => $config_file,
99110
content => template('haproxy/haproxy_frontend_block.erb'),
100111
}
101112
}

manifests/init.pp

Lines changed: 39 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,26 @@
1212
# === Parameters
1313
#
1414
# [*package_ensure*]
15-
# Chooses whether the haproxy package should be installed or uninstalled. Defaults to 'present'
15+
# Chooses whether the haproxy package should be installed or uninstalled.
16+
# Defaults to 'present'
1617
#
1718
# [*package_name*]
1819
# The package name of haproxy. Defaults to 'haproxy'
20+
# NOTE: haproxy::instance has a different default.
1921
#
2022
# [*service_ensure*]
2123
# Chooses whether the haproxy service should be running & enabled at boot, or
2224
# stopped and disabled at boot. Defaults to 'running'
2325
#
2426
# [*service_manage*]
25-
# Chooses whether the haproxy service state should be managed by puppet at all. Defaults to true
27+
# Chooses whether the haproxy service state should be managed by puppet at
28+
# all. Defaults to true
29+
#
30+
# [*service_options*]
31+
# Contents for the `/etc/defaults/haproxy` file on Debian. Defaults to "ENABLED=1\n" on Debian, and is ignored on other systems.
32+
#
33+
# [*service_options*]
34+
# Contents for the `/etc/defaults/haproxy` file on Debian. Defaults to "ENABLED=1\n" on Debian, and is ignored on other systems.
2635
#
2736
# [*global_options*]
2837
# A hash of all the haproxy global options. If you want to specify more
@@ -36,6 +45,12 @@
3645
# options as an array and you will get a line for each of them in the
3746
# resultant haproxy.cfg file.
3847
#
48+
# [*merge_options*]
49+
# Whether to merge the user-supplied `global_options`/`defaults_options`
50+
# hashes with their default values set in params.pp. Merging allows to change
51+
# or add options without having to recreate the entire hash. Defaults to
52+
# false, but will default to true in future releases.
53+
#
3954
#[*restart_command*]
4055
# Command to use when restarting the on config changes.
4156
# Passed directly as the <code>'restart'</code> parameter to the service resource.
@@ -83,8 +98,10 @@
8398
$package_name = $haproxy::params::package_name,
8499
$service_ensure = 'running',
85100
$service_manage = true,
101+
$service_options = $haproxy::params::service_options,
86102
$global_options = $haproxy::params::global_options,
87103
$defaults_options = $haproxy::params::defaults_options,
104+
$merge_options = $haproxy::params::merge_options,
88105
$restart_command = undef,
89106
$custom_fragment = undef,
90107
$config_file = $haproxy::params::config_file,
@@ -101,6 +118,13 @@
101118
}
102119
validate_string($package_name,$package_ensure)
103120
validate_bool($service_manage)
121+
validate_bool($merge_options)
122+
validate_string($service_options)
123+
124+
# NOTE: These deprecating parameters are implemented in this class,
125+
# not in haproxy::instance. haproxy::instance is new and therefore
126+
# there should be no legacy code that uses these deprecated
127+
# parameters.
104128

105129
# To support deprecating $enable
106130
if $enable != undef {
@@ -125,17 +149,18 @@
125149
$_service_manage = $service_manage
126150
}
127151

128-
if $_package_ensure == 'absent' or $_package_ensure == 'purged' {
129-
anchor { 'haproxy::begin': }
130-
~> class { 'haproxy::service': }
131-
-> class { 'haproxy::config': }
132-
-> class { 'haproxy::install': }
133-
-> anchor { 'haproxy::end': }
134-
} else {
135-
anchor { 'haproxy::begin': }
136-
-> class { 'haproxy::install': }
137-
-> class { 'haproxy::config': }
138-
~> class { 'haproxy::service': }
139-
-> anchor { 'haproxy::end': }
152+
haproxy::instance{ $title:
153+
package_ensure => $_package_ensure,
154+
package_name => $package_name,
155+
service_ensure => $_service_ensure,
156+
service_manage => $_service_manage,
157+
global_options => $global_options,
158+
defaults_options => $defaults_options,
159+
restart_command => $restart_command,
160+
custom_fragment => $custom_fragment,
161+
config_file => $config_file,
162+
merge_options => $merge_options,
163+
service_options => $service_options,
140164
}
165+
141166
}

manifests/install.pp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
11
# Private class
2-
class haproxy::install inherits haproxy {
2+
define haproxy::install (
3+
$package_ensure,
4+
$package_name = undef, # A default is required for Puppet 2.7 compatibility. When 2.7 is no longer supported, this parameter default should be removed.
5+
) {
36
if $caller_module_name != $module_name {
47
fail("Use of private class ${name} by ${caller_module_name}")
58
}
69

7-
package { $haproxy::package_name:
8-
ensure => $haproxy::_package_ensure,
9-
alias => 'haproxy',
10+
if $package_name != undef {
11+
package { $package_name:
12+
ensure => $package_ensure,
13+
alias => 'haproxy',
14+
}
1015
}
1116

1217
# Create default configuration directory, gentoo portage does not create it

0 commit comments

Comments
 (0)