Skip to content

Commit a32adb5

Browse files
committed
(CONT-1144) - Conversion of ERB to EPP templates
1 parent 69d41eb commit a32adb5

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+411
-234
lines changed

REFERENCE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1247,7 +1247,7 @@ Data type: `String`
12471247

12481248
The template that will be used to create an unit file.
12491249

1250-
Default value: `'haproxy/instance_service_unit.erb'`
1250+
Default value: `'haproxy/instance_service_unit.epp'`
12511251

12521252
### <a name="haproxy--listen"></a>`haproxy::listen`
12531253

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# frozen_string_literal: true
2+
3+
# Function created to generate error message. Any string as error message can be passed and the function can
4+
# be called in epp templates.
5+
6+
Puppet::Functions.create_function(:'haproxy::generate_error_message') do
7+
dispatch :generate_error_message do
8+
param 'String', :error_message
9+
end
10+
11+
def generate_error_message(error_message)
12+
raise(error_message)
13+
end
14+
end
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# frozen_string_literal: true
2+
3+
Puppet::Functions.create_function(:'haproxy::sort_bind') do
4+
dispatch :sort_bind do
5+
param 'Hash', :bind
6+
return_type 'Array'
7+
end
8+
9+
def sort_bind(bind)
10+
bind.sort_by do |address_port|
11+
md = %r{^((\d+)\.(\d+)\.(\d+)\.(\d+))?(.*)}.match(address_port[0])
12+
[(md[1] ? md[2..5].inject(0) { |addr, octet| (addr << 8) + octet.to_i } : -1), md[6]]
13+
end
14+
end
15+
end
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# frozen_string_literal: true
2+
3+
require 'ipaddr'
4+
5+
Puppet::Functions.create_function(:'haproxy::validate_ip_addr') do
6+
dispatch :validate_ip_addr do
7+
param 'String', :virtual_ip
8+
return_type 'Boolean'
9+
end
10+
11+
def validate_ip_addr(virtual_ip)
12+
IPAddr.new(virtual_ip)
13+
true
14+
rescue StandardError
15+
false
16+
end
17+
end

manifests/backend.pp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,11 +125,19 @@
125125
$order = "25-${defaults}-${section_name}-01"
126126
}
127127

128+
$parameters = {
129+
'section_name' => $section_name,
130+
'mode' => $mode,
131+
'description' => $description,
132+
'_sort_options_alphabetic' => $_sort_options_alphabetic,
133+
'options' => $options,
134+
}
135+
128136
# Template uses: $section_name, $ipaddress, $ports, $options
129137
concat::fragment { "${instance_name}-${section_name}_backend_block":
130138
order => $order,
131139
target => $_config_file,
132-
content => template('haproxy/haproxy_backend_block.erb'),
140+
content => epp('haproxy/haproxy_backend_block.epp', $parameters),
133141
}
134142

135143
if $collect_exported {

manifests/balancermember.pp

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,10 +167,25 @@
167167
} else {
168168
$order = "25-${defaults}-${listening_service}-02-${name}"
169169
}
170+
171+
$parameters = {
172+
'type' => $type,
173+
'ipaddresses' => $ipaddresses,
174+
'server_names' => $server_names,
175+
'ports' => $ports,
176+
'define_cookies' => $define_cookies,
177+
'options' => $options,
178+
'verifyhost' => $verifyhost,
179+
'weight' => $weight,
180+
'prefix' => $prefix,
181+
'amount' => $amount,
182+
'fqdn' => $fqdn,
183+
'port' => $port,
184+
}
170185
# Template uses $ipaddresses, $server_name, $ports, $option
171186
concat::fragment { "${instance_name}-${listening_service}_balancermember_${name}":
172187
order => $order,
173188
target => $_config_file,
174-
content => template('haproxy/haproxy_balancermember.erb'),
189+
content => epp('haproxy/haproxy_balancermember.epp', $parameters),
175190
}
176191
}

manifests/config.pp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,17 @@
7070
content => "# This file is managed by Puppet\n",
7171
}
7272

73+
$parameters = {
74+
'_global_options' => $_global_options,
75+
'_defaults_options' => $_defaults_options,
76+
'custom_fragment' => $custom_fragment,
77+
}
78+
7379
# Template uses $_global_options, $_defaults_options, $custom_fragment
7480
concat::fragment { "${instance_name}-haproxy-base":
7581
target => $_config_file,
7682
order => '10',
77-
content => template("${module_name}/haproxy-base.cfg.erb"),
83+
content => epp("${module_name}/haproxy-base.cfg.epp", $parameters),
7884
}
7985
}
8086

manifests/defaults.pp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,15 @@
3636
include haproxy::globals
3737
$_sort_options_alphabetic = pick($sort_options_alphabetic, $haproxy::globals::sort_options_alphabetic)
3838

39+
$parameters = {
40+
'_sort_options_alphabetic' => $_sort_options_alphabetic,
41+
'options' => $options,
42+
'name' => $name,
43+
}
44+
3945
concat::fragment { "${instance_name}-${name}_defaults_block":
4046
order => "25-${name}",
4147
target => $config_file,
42-
content => template('haproxy/haproxy_defaults_block.erb'),
48+
content => epp('haproxy/haproxy_defaults_block.epp', $parameters),
4349
}
4450
}

manifests/frontend.pp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,10 +143,23 @@
143143
$order = "25-${defaults}-${section_name}-00"
144144
}
145145
}
146+
147+
$parameters = {
148+
'section_name' => $section_name,
149+
'bind' => $bind,
150+
'ipaddress' => $ipaddress,
151+
'ports' => $ports,
152+
'bind_options' => $bind_options,
153+
'mode' => $mode,
154+
'description' => $description,
155+
'options' => $options,
156+
'_sort_options_alphabetic' => $_sort_options_alphabetic,
157+
}
158+
146159
# Template uses: $section_name, $ipaddress, $ports, $options
147160
concat::fragment { "${instance_name}-${section_name}_frontend_block":
148161
order => $order,
149162
target => $_config_file,
150-
content => template('haproxy/haproxy_frontend_block.erb'),
163+
content => epp('haproxy/haproxy_frontend_block.epp', $parameters),
151164
}
152165
}

manifests/instance_service.pp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
#
4343
define haproxy::instance_service (
4444
Optional[String] $haproxy_init_source = undef,
45-
String $haproxy_unit_template = 'haproxy/instance_service_unit.erb',
45+
String $haproxy_unit_template = 'haproxy/instance_service_unit.epp',
4646
String $haproxy_package = 'haproxy',
4747
Stdlib::Absolutepath $bindir = '/opt/haproxy/bin',
4848
) {
@@ -103,12 +103,16 @@
103103
$unitfile = "/lib/systemd/system/haproxy-${title}.service"
104104
}
105105

106+
$parameters = {
107+
'title' => $title,
108+
'wrapper' => $wrapper,
109+
}
106110
file { $unitfile:
107111
ensure => file,
108112
mode => '0644',
109113
owner => 'root',
110114
group => 'root',
111-
content => template($haproxy_unit_template),
115+
content => epp($haproxy_unit_template, $parameters),
112116
notify => Exec['systemctl daemon-reload'],
113117
}
114118
if (!defined(Exec['systemctl daemon-reload'])) {

0 commit comments

Comments
 (0)