forked from glarizza/puppet-haproxy
-
Notifications
You must be signed in to change notification settings - Fork 268
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow greater flexibility in listen directive.
Currently the module does not allow to specify specific bind options per IP we are binding haproxy onto. Hence, if a user has a service available across several network, but with different haproxy bind option according to the network, s/he can't configure haproxy with the current state of this module. It aims to make it possible to have configuration as the following: bind 192.168.2.1:80 ssl crt public.puppetlabs.com.crt bind 10.0.0.1:80 ssl crt private.puppetlabs.com.crt bind 178.35.67.12:80
- Loading branch information
Showing
6 changed files
with
161 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,34 @@ | ||
<% require 'ipaddr' -%> | ||
<% Array(@ipaddress).uniq.each do |virtual_ip| (@ports.is_a?(Array) ? @ports : Array(@ports.split(","))).each do |port| -%> | ||
<%- | ||
begin | ||
IPAddr.new(virtual_ip) | ||
valid_ip = true | ||
rescue ArgumentError => e | ||
valid_ip = false | ||
end | ||
if ! valid_ip and ! virtual_ip.match(/^[A-Za-z][A-Za-z0-9\.-]+$/) and virtual_ip != "*" | ||
scope.function_fail(["Invalid IP address or hostname [#{virtual_ip}]"]) | ||
end | ||
-%> | ||
<%- scope.function_fail(["Port [#{port}] is outside of range 1-65535"]) if port.to_i < 1 or port.to_i > 65535 -%> | ||
bind <%= virtual_ip %>:<%= port %> <%= Array(@bind_options).join(" ") %> | ||
<% end end -%> | ||
<% if @bind | ||
@bind.keys.uniq.sort.each do |virtual_ip| | ||
if ip_port = virtual_ip.match(/^([A-Za-z0-9\.-]+):([0-9]+)$/) | ||
ip = ip_port[1] | ||
port = ip_port[2] | ||
elsif virtual_ip.match(/^([A-Za-z0-9\.-]+)$/) | ||
ip = virtual_ip | ||
end | ||
begin | ||
IPAddr.new(ip) | ||
valid_ip = true | ||
rescue ArgumentError => e | ||
valid_ip = false | ||
end | ||
if ! valid_ip and ! ip.match(/^[A-Za-z][A-Za-z0-9\.-]+$/) and ip != "*" | ||
scope.function_fail(["Invalid IP address or hostname [#{ip}]"]) | ||
end | ||
scope.function_fail(["Port #{port} for IP #{ip} is outside of range 1-65535"]) if port and (port.to_i < 1 or port.to_i > 65535) -%> | ||
bind <%= ip -%>:<%= port -%> <%= Array(@bind[virtual_ip]).join(" ") %> | ||
<%- end else | ||
Array(@ipaddress).uniq.each do |virtual_ip| (@ports.is_a?(Array) ? @ports : Array(@ports.split(","))).each do |port| | ||
begin | ||
IPAddr.new(virtual_ip) | ||
valid_ip = true | ||
rescue ArgumentError => e | ||
valid_ip = false | ||
end | ||
if ! valid_ip and ! virtual_ip.match(/^[A-Za-z][A-Za-z0-9\.-]+$/) and virtual_ip != "*" | ||
scope.function_fail(["Invalid IP address or hostname [#{virtual_ip}]"]) | ||
end | ||
scope.function_fail(["Port [#{port}] is outside of range 1-65535"]) if port.to_i < 1 or port.to_i > 65535 -%> | ||
bind <%= virtual_ip -%>:<%= port -%> <%= Array(@bind_options).join(" ") %> | ||
<%- end end end -%> |
Since
$ipaddress
always has a value, this is always true if one attempts to use$bind
. Settingipaddress => ''
causes the templates to error, andipaddress => undef
asks puppet to use the default value, which isn't helpful.