summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gemfile5
-rw-r--r--.travis.yml23
-rw-r--r--manifests/listen.pp4
-rw-r--r--spec/defines/listen_spec.rb12
-rw-r--r--templates/haproxy_listen_block.erb6
5 files changed, 40 insertions, 10 deletions
diff --git a/.gemfile b/.gemfile
new file mode 100644
index 0000000..9aad840
--- /dev/null
+++ b/.gemfile
@@ -0,0 +1,5 @@
+source :rubygems
+
+puppetversion = ENV.key?('PUPPET_VERSION') ? "= #{ENV['PUPPET_VERSION']}" : ['>= 2.7']
+gem 'puppet', puppetversion
+gem 'puppetlabs_spec_helper', '>= 0.1.0'
diff --git a/.travis.yml b/.travis.yml
new file mode 100644
index 0000000..fdbc95d
--- /dev/null
+++ b/.travis.yml
@@ -0,0 +1,23 @@
+language: ruby
+rvm:
+ - 1.8.7
+ - 1.9.3
+script: "rake spec"
+branches:
+ only:
+ - master
+env:
+ - PUPPET_VERSION=2.6.17
+ - PUPPET_VERSION=2.7.19
+ #- PUPPET_VERSION=3.0.1 # Breaks due to rodjek/rspec-puppet#58
+notifications:
+ email: false
+gemfile: .gemfile
+matrix:
+ exclude:
+ - rvm: 1.9.3
+ gemfile: .gemfile
+ env: PUPPET_VERSION=2.6.17
+ - rvm: 1.8.7
+ gemfile: .gemfile
+ env: PUPPET_VERSION=3.0.1
diff --git a/manifests/listen.pp b/manifests/listen.pp
index 5dea8a8..00636e3 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 = {
@@ -82,7 +82,7 @@ define haproxy::listen (
) {
# Template uses: $name, $ipaddress, $ports, $options
concat::fragment { "${name}_listen_block":
- order => "20-${name}",
+ order => "20-${name}-00",
target => '/etc/haproxy/haproxy.cfg',
content => template('haproxy/haproxy_listen_block.erb'),
}
diff --git a/spec/defines/listen_spec.rb b/spec/defines/listen_spec.rb
index fa54409..31dd4c8 100644
--- a/spec/defines/listen_spec.rb
+++ b/spec/defines/listen_spec.rb
@@ -12,9 +12,9 @@ describe 'haproxy::listen' do
end
it { should contain_concat__fragment('croy_listen_block').with(
- 'order' => '20-croy',
+ 'order' => '20-croy-00',
'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
@@ -30,9 +30,9 @@ describe 'haproxy::listen' do
end
it { should contain_concat__fragment('apache_listen_block').with(
- 'order' => '20-apache',
+ 'order' => '20-apache-00',
'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
@@ -45,9 +45,9 @@ describe 'haproxy::listen' do
end
it { should contain_concat__fragment('apache_listen_block').with(
- 'order' => '20-apache',
+ 'order' => '20-apache-00',
'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 4cd8feb..ede7db4 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| -%>
<% Array(val).each do |item| -%>
<%= key %> <%= item %>