module-nginx/templates/conf.d/geo.erb

34 lines
841 B
Text
Raw Normal View History

# MANAGED BY PUPPET
2014-06-12 20:12:24 +02:00
<%
# sorting ip addresses in ascending order is more efficient for nginx - so we need
# to convert them to numbers first via IPAddr
require 'ipaddr'
-%>
geo <%= @address ? "#{@address} " : '' %>$<%= @name %> {
<% if @ranges -%>
ranges;
<% end -%>
<% if @default -%>
default <%= @default %>;
<% end -%>
<% if @delete -%>
delete <%= @delete %>;
2014-06-12 20:12:24 +02:00
<% end -%>
<% if @proxies -%>
<%- if @proxy_recursive -%>
proxy_recursive;
<%- end -%>
2014-06-12 20:12:24 +02:00
<%- [@proxies].flatten.each do |proxy| -%>
proxy <%= proxy %>;
<%- end -%>
<% end -%>
<% if @networks -%>
<%- field_width = @networks.inject(0) { |l,(k,v)| k.size > l ? k.size : l } -%>
2014-06-12 20:12:24 +02:00
<%- @networks.sort_by{|k,v| IPAddr.new(k.split('-').first).to_i }.each do |key,value| -%>
<%= sprintf("%-*s", field_width, key) %> <%= value %>;
2014-06-12 20:12:24 +02:00
<%- end -%>
<% end -%>
}