From 3624b0b5f6a18d000ef3b7723f10579d448a4063 Mon Sep 17 00:00:00 2001 From: Eugene Kirpichov Date: Tue, 6 Nov 2012 19:08:44 +0400 Subject: Listen on multiple virtual IP addresses --- manifests/listen.pp | 2 +- spec/defines/listen_spec.rb | 6 +++--- templates/haproxy_listen_block.erb | 6 ++++-- 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| -%> -- cgit v1.2.3