Skip to content

Commit

Permalink
Merge pull request #82 from misterdorm/bindoptions
Browse files Browse the repository at this point in the history
Add haproxy::listen bind_options parameter for setting arbitrary 'bind' options
  • Loading branch information
hunner committed May 19, 2014
2 parents ff713f8 + 78c0e2a commit b35edfa
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 5 deletions.
7 changes: 6 additions & 1 deletion manifests/listen.pp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@
# A hash of options that are inserted into the listening service
# configuration block.
#
# [*bind_options*]
# An array of options to be specified after the bind declaration in the
# listening serivce's configuration block.
#
# [*collect_exported*]
# Boolean, default 'true'. True means 'collect exported @@balancermember resources'
# (for the case when every balancermember node exports itself), false means
Expand Down Expand Up @@ -77,7 +81,8 @@
'ssl-hello-chk'
],
'balance' => 'roundrobin'
}
},
$bind_options = ''
) {

# Template uses: $name, $ipaddress, $ports, $options
Expand Down
21 changes: 18 additions & 3 deletions spec/defines/listen_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
it { should contain_concat__fragment('croy_listen_block').with(
'order' => '20-croy-00',
'target' => '/etc/haproxy/haproxy.cfg',
'content' => "\nlisten croy\n bind 1.1.1.1:18140\n balance roundrobin\n option tcplog\n option ssl-hello-chk\n"
'content' => "\nlisten croy\n bind 1.1.1.1:18140 \n balance roundrobin\n option tcplog\n option ssl-hello-chk\n"
) }
end
context "when an array of ports is provided" do
Expand All @@ -32,7 +32,7 @@
it { should contain_concat__fragment('apache_listen_block').with(
'order' => '20-apache-00',
'target' => '/etc/haproxy/haproxy.cfg',
'content' => "\nlisten apache\n bind 23.23.23.23:80\n bind 23.23.23.23:443\n balance roundrobin\n option tcplog\n option ssl-hello-chk\n"
'content' => "\nlisten apache\n bind 23.23.23.23:80 \n bind 23.23.23.23:443 \n balance roundrobin\n option tcplog\n option ssl-hello-chk\n"
) }
end
context "when a comma-separated list of ports is provided" do
Expand All @@ -47,7 +47,22 @@
it { should contain_concat__fragment('apache_listen_block').with(
'order' => '20-apache-00',
'target' => '/etc/haproxy/haproxy.cfg',
'content' => "\nlisten apache\n bind 23.23.23.23:80\n bind 23.23.23.23:443\n balance roundrobin\n option tcplog\n option ssl-hello-chk\n"
'content' => "\nlisten apache\n bind 23.23.23.23:80 \n bind 23.23.23.23:443 \n balance roundrobin\n option tcplog\n option ssl-hello-chk\n"
) }
end
context "when bind options are provided" do
let(:params) do
{
:name => 'apache',
:ports => '80',
:bind_options => [ 'the options', 'go here' ]
}
end

it { should contain_concat__fragment('apache_listen_block').with(
'order' => '20-apache-00',
'target' => '/etc/haproxy/haproxy.cfg',
'content' => "\nlisten apache\n bind 1.1.1.1:80 the options go here\n balance roundrobin\n option tcplog\n option ssl-hello-chk\n"
) }
end
end
2 changes: 1 addition & 1 deletion templates/haproxy_listen_block.erb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

listen <%= @name %>
<% Array(@ipaddress).uniq.each do |virtual_ip| (@ports.is_a?(Array) ? @ports : Array(@ports.split(","))).each do |port| -%>
bind <%= virtual_ip %>:<%= port %>
bind <%= virtual_ip %>:<%= port %> <%= Array(@bind_options).join(" ") %>
<% end end -%>
<% if @mode -%>
mode <%= @mode %>
Expand Down

0 comments on commit b35edfa

Please sign in to comment.