summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEugene Kirpichov <ekirpichov@gmail.com>2012-11-06 19:08:44 +0400
committerEugene Kirpichov <ekirpichov@gmail.com>2012-11-06 19:09:12 +0400
commit3624b0b5f6a18d000ef3b7723f10579d448a4063 (patch)
tree2f1863604dc90c5428d602a83e9400405333b450
parent161f257017f4bc51e08bcc6fa2f29c0674b5ce0e (diff)
Listen on multiple virtual IP addresses
-rw-r--r--manifests/listen.pp2
-rw-r--r--spec/defines/listen_spec.rb6
-rw-r--r--templates/haproxy_listen_block.erb6
3 files changed, 8 insertions, 6 deletions
diff --git a/manifests/listen.pp b/manifests/listen.pp
index 5dea8a8..ee9e320 100644
--- a/manifests/listen.pp
+++ b/manifests/listen.pp
@@ -69,7 +69,7 @@
#
define haproxy::listen (
$ports,
- $ipaddress = $::ipaddress,
+ $ipaddress = [$::ipaddress],
$mode = 'tcp',
$collect_exported = true,
$options = {
diff --git a/spec/defines/listen_spec.rb b/spec/defines/listen_spec.rb
index fa54409..6102285 100644
--- a/spec/defines/listen_spec.rb
+++ b/spec/defines/listen_spec.rb
@@ -14,7 +14,7 @@ describe 'haproxy::listen' do
it { should contain_concat__fragment('croy_listen_block').with(
'order' => '20-croy',
'target' => '/etc/haproxy/haproxy.cfg',
- 'content' => "\nlisten croy 1.1.1.1:18140\n balance roundrobin\n option tcplog\n option ssl-hello-chk\n"
+ 'content' => "listen croy\n\n bind 1.1.1.1:18140\n\n balance roundrobin\n option tcplog\n option ssl-hello-chk\n"
) }
end
context "when an array of ports is provided" do
@@ -32,7 +32,7 @@ describe 'haproxy::listen' do
it { should contain_concat__fragment('apache_listen_block').with(
'order' => '20-apache',
'target' => '/etc/haproxy/haproxy.cfg',
- 'content' => "\nlisten apache 23.23.23.23:80,23.23.23.23:443\n balance roundrobin\n option tcplog\n option ssl-hello-chk\n"
+ 'content' => "listen apache\n\n bind 23.23.23.23:80\n\n bind 23.23.23.23:443\n\n balance roundrobin\n option tcplog\n option ssl-hello-chk\n"
) }
end
context "when a comma-separated list of ports is provided" do
@@ -47,7 +47,7 @@ describe 'haproxy::listen' do
it { should contain_concat__fragment('apache_listen_block').with(
'order' => '20-apache',
'target' => '/etc/haproxy/haproxy.cfg',
- 'content' => "\nlisten apache 23.23.23.23:80,23.23.23.23:443\n balance roundrobin\n option tcplog\n option ssl-hello-chk\n"
+ 'content' => "listen apache\n\n bind 23.23.23.23:80\n\n bind 23.23.23.23:443\n\n balance roundrobin\n option tcplog\n option ssl-hello-chk\n"
) }
end
end
diff --git a/templates/haproxy_listen_block.erb b/templates/haproxy_listen_block.erb
index 12f55f6..8b3767f 100644
--- a/templates/haproxy_listen_block.erb
+++ b/templates/haproxy_listen_block.erb
@@ -1,5 +1,7 @@
-
-listen <%= name %> <%= ipaddress %>:<%= Array(ports).collect { |x| x.split(',')}.flatten.join(",#{ipaddress}:") %>
+listen <%= name %>
+<% Array(ipaddress).uniq.each do |virtual_ip| (ports.is_a?(Array) ? ports : Array(ports.split(","))).each do |port| %>
+ bind <%= virtual_ip %>:<%= port %>
+<% end end %>
<% options.sort.each do |key, val| -%>
<% if val.is_a?(Array) -%>
<% val.each do |item| -%>